
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>状态管理 · 《Terraform入门教程》</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="大可不加冰">
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-prism/prism-vsc-dark-plus.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="3.Terraform代码的书写.html" />
    
    
    <link rel="prev" href="2.1.Terraform基础概念——Provider.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.1.</b>
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="1.Terraform初步体验.html">
            
                <a href="1.Terraform初步体验.html">
            
                    
                        <b>1.2.</b>
                    
                    Terraform 初步体验
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                        <b>1.3.</b>
                    
                    Terraform基础概念
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="2.1.Terraform基础概念——Provider.html">
            
                <a href="2.1.Terraform基础概念——Provider.html">
            
                    
                        <b>1.3.1.</b>
                    
                    Provider
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.2" data-path="2.2.Terraform基础概念——状态管理.html">
            
                <a href="2.2.Terraform基础概念——状态管理.html">
            
                    
                        <b>1.3.2.</b>
                    
                    状态管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="3.Terraform代码的书写.html">
            
                <a href="3.Terraform代码的书写.html">
            
                    
                        <b>1.4.</b>
                    
                    Terraform 代码的书写
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="3.1.类型.html">
            
                <a href="3.1.类型.html">
            
                    
                        <b>1.4.1.</b>
                    
                    类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="3.2.配置语法.html">
            
                <a href="3.2.配置语法.html">
            
                    
                        <b>1.4.2.</b>
                    
                    配置语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="3.3.输入变量.html">
            
                <a href="3.3.输入变量.html">
            
                    
                        <b>1.4.3.</b>
                    
                    输入变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="3.4.输出值.html">
            
                <a href="3.4.输出值.html">
            
                    
                        <b>1.4.4.</b>
                    
                    输出值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="3.5.局部值.html">
            
                <a href="3.5.局部值.html">
            
                    
                        <b>1.4.5.</b>
                    
                    局部值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="3.6.资源.html">
            
                <a href="3.6.资源.html">
            
                    
                        <b>1.4.6.</b>
                    
                    资源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="3.7.数据源.html">
            
                <a href="3.7.数据源.html">
            
                    
                        <b>1.4.7.</b>
                    
                    数据源
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="3.8.表达式.html">
            
                <a href="3.8.表达式.html">
            
                    
                        <b>1.4.8.</b>
                    
                    表达式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="3.9.重载文件.html">
            
                <a href="3.9.重载文件.html">
            
                    
                        <b>1.4.9.</b>
                    
                    重载文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="3.10.代码风格规范.html">
            
                <a href="3.10.代码风格规范.html">
            
                    
                        <b>1.4.10.</b>
                    
                    代码风格规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="3.11.checks.html">
            
                <a href="3.11.checks.html">
            
                    
                        <b>1.4.11.</b>
                    
                    Checks
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="4.Terraform模块.html">
            
                <a href="4.Terraform模块.html">
            
                    
                        <b>1.5.</b>
                    
                    Terraform 模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="4.1.创建模块.html">
            
                <a href="4.1.创建模块.html">
            
                    
                        <b>1.5.1.</b>
                    
                    创建模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="4.2.使用模块.html">
            
                <a href="4.2.使用模块.html">
            
                    
                        <b>1.5.2.</b>
                    
                    使用模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="4.3.模块元参数.html">
            
                <a href="4.3.模块元参数.html">
            
                    
                        <b>1.5.3.</b>
                    
                    模块元参数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="4.4.重构.html">
            
                <a href="4.4.重构.html">
            
                    
                        <b>1.5.4.</b>
                    
                    重构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="4.5.设计新模块的模式.html">
            
                <a href="4.5.设计新模块的模式.html">
            
                    
                        <b>1.5.5.</b>
                    
                    设计新模块的模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="5.Terraform命令行.html">
            
                <a href="5.Terraform命令行.html">
            
                    
                        <b>1.6.</b>
                    
                    Terraform 命令行
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="5.1.命令行配置文件.html">
            
                <a href="5.1.命令行配置文件.html">
            
                    
                        <b>1.6.1.</b>
                    
                    命令行配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="5.2.环境变量.html">
            
                <a href="5.2.环境变量.html">
            
                    
                        <b>1.6.2.</b>
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="5.3.资源地址.html">
            
                <a href="5.3.资源地址.html">
            
                    
                        <b>1.6.3.</b>
                    
                    资源地址
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="5.4.apply.html">
            
                <a href="5.4.apply.html">
            
                    
                        <b>1.6.4.</b>
                    
                    apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="5.5.console.html">
            
                <a href="5.5.console.html">
            
                    
                        <b>1.6.5.</b>
                    
                    console
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="5.6.destroy.html">
            
                <a href="5.6.destroy.html">
            
                    
                        <b>1.6.6.</b>
                    
                    destroy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="5.7.fmt.html">
            
                <a href="5.7.fmt.html">
            
                    
                        <b>1.6.7.</b>
                    
                    fmt
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="5.8.force-unlock.html">
            
                <a href="5.8.force-unlock.html">
            
                    
                        <b>1.6.8.</b>
                    
                    force-unlock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="5.9.get.html">
            
                <a href="5.9.get.html">
            
                    
                        <b>1.6.9.</b>
                    
                    get
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="5.10.graph.html">
            
                <a href="5.10.graph.html">
            
                    
                        <b>1.6.10.</b>
                    
                    graph
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="5.11.import.html">
            
                <a href="5.11.import.html">
            
                    
                        <b>1.6.11.</b>
                    
                    import
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" data-path="5.12.init.html">
            
                <a href="5.12.init.html">
            
                    
                        <b>1.6.12.</b>
                    
                    init
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.13" data-path="5.13.output.html">
            
                <a href="5.13.output.html">
            
                    
                        <b>1.6.13.</b>
                    
                    output
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.14" data-path="5.14.plan.html">
            
                <a href="5.14.plan.html">
            
                    
                        <b>1.6.14.</b>
                    
                    plan
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.15" data-path="5.15.providers.html">
            
                <a href="5.15.providers.html">
            
                    
                        <b>1.6.15.</b>
                    
                    providers
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.15.1" data-path="5.15.1.mirror.html">
            
                <a href="5.15.1.mirror.html">
            
                    
                        <b>1.6.15.1.</b>
                    
                    mirror
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.15.2" data-path="5.15.2.schema.html">
            
                <a href="5.15.2.schema.html">
            
                    
                        <b>1.6.15.2.</b>
                    
                    schema
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.16" data-path="5.16.refresh.html">
            
                <a href="5.16.refresh.html">
            
                    
                        <b>1.6.16.</b>
                    
                    refresh
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.17" data-path="5.17.show.html">
            
                <a href="5.17.show.html">
            
                    
                        <b>1.6.17.</b>
                    
                    show
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18" data-path="5.18.state.html">
            
                <a href="5.18.state.html">
            
                    
                        <b>1.6.18.</b>
                    
                    state
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.18.1" data-path="5.18.1.list.html">
            
                <a href="5.18.1.list.html">
            
                    
                        <b>1.6.18.1.</b>
                    
                    list
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.2" data-path="5.18.2.mv.html">
            
                <a href="5.18.2.mv.html">
            
                    
                        <b>1.6.18.2.</b>
                    
                    mv
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.3" data-path="5.18.3.pull.html">
            
                <a href="5.18.3.pull.html">
            
                    
                        <b>1.6.18.3.</b>
                    
                    pull
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.4" data-path="5.18.4.push.html">
            
                <a href="5.18.4.push.html">
            
                    
                        <b>1.6.18.4.</b>
                    
                    push
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.5" data-path="5.18.5.replace-provider.html">
            
                <a href="5.18.5.replace-provider.html">
            
                    
                        <b>1.6.18.5.</b>
                    
                    replace-provider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.6" data-path="5.18.6.rm.html">
            
                <a href="5.18.6.rm.html">
            
                    
                        <b>1.6.18.6.</b>
                    
                    rm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.18.7" data-path="5.18.7.show.html">
            
                <a href="5.18.7.show.html">
            
                    
                        <b>1.6.18.7.</b>
                    
                    show
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.19" data-path="5.19.taint.html">
            
                <a href="5.19.taint.html">
            
                    
                        <b>1.6.19.</b>
                    
                    taint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.20" data-path="5.20.validate.html">
            
                <a href="5.20.validate.html">
            
                    
                        <b>1.6.20.</b>
                    
                    validate
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.21" data-path="5.21.untaint.html">
            
                <a href="5.21.untaint.html">
            
                    
                        <b>1.6.21.</b>
                    
                    untaint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22" data-path="5.22.workspace.html">
            
                <a href="5.22.workspace.html">
            
                    
                        <b>1.6.22.</b>
                    
                    workspace
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.22.1" data-path="5.22.1.list.html">
            
                <a href="5.22.1.list.html">
            
                    
                        <b>1.6.22.1.</b>
                    
                    list
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.2" data-path="5.22.2.select.html">
            
                <a href="5.22.2.select.html">
            
                    
                        <b>1.6.22.2.</b>
                    
                    select
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.3" data-path="5.22.3.new.html">
            
                <a href="5.22.3.new.html">
            
                    
                        <b>1.6.22.3.</b>
                    
                    new
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.4" data-path="5.22.4.delete.html">
            
                <a href="5.22.4.delete.html">
            
                    
                        <b>1.6.22.4.</b>
                    
                    delete
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.22.5" data-path="5.22.5.show.html">
            
                <a href="5.22.5.show.html">
            
                    
                        <b>1.6.22.5.</b>
                    
                    show
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="6.test.html">
            
                <a href="6.test.html">
            
                    
                        <b>1.7.</b>
                    
                    Terraform Test
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="7.Aha——会心一击.html">
            
                <a href="7.Aha——会心一击.html">
            
                    
                        <b>1.8.</b>
                    
                    Aha——会心一击
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="7.1.有条件创建.html">
            
                <a href="7.1.有条件创建.html">
            
                    
                        <b>1.8.1.</b>
                    
                    有条件创建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="7.2.依赖反转.html">
            
                <a href="7.2.依赖反转.html">
            
                    
                        <b>1.8.2.</b>
                    
                    依赖反转
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="7.3.多可用区分布.html">
            
                <a href="7.3.多可用区分布.html">
            
                    
                        <b>1.8.3.</b>
                    
                    多可用区分布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="7.4.provisioner与user_data.html">
            
                <a href="7.4.provisioner与user_data.html">
            
                    
                        <b>1.8.4.</b>
                    
                    provisioner与user_data
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="7.5.destroy-provisioner中使用变量.html">
            
                <a href="7.5.destroy-provisioner中使用变量.html">
            
                    
                        <b>1.8.5.</b>
                    
                    destroy-provisioner中使用变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="7.6.利用null_resource的triggers触发其他资源更新.html">
            
                <a href="7.6.利用null_resource的triggers触发其他资源更新.html">
            
                    
                        <b>1.8.6.</b>
                    
                    利用null_resource的triggers触发其他资源更新
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="7.7.利用null_resource搭配replace_triggered_by更新无法读取的属性.html">
            
                <a href="7.7.利用null_resource搭配replace_triggered_by更新无法读取的属性.html">
            
                    
                        <b>1.8.7.</b>
                    
                    利用 null_resource 搭配 replace_triggered_by 更新无法从服务端读取内容的属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="7.8.创建资源的条件依赖另一个资源的输出时怎么办.html">
            
                <a href="7.8.创建资源的条件依赖另一个资源的输出时怎么办.html">
            
                    
                        <b>1.8.8.</b>
                    
                    创建资源的条件依赖另一个资源的输出时怎么办
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="7.9.利用create_before_destroy调整资源update执行的顺序.html">
            
                <a href="7.9.利用create_before_destroy调整资源update执行的顺序.html">
            
                    
                        <b>1.8.9.</b>
                    
                    利用 create_before_destroy 调整资源 Update 的执行顺序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="7.10.terraform与自动化.html">
            
                <a href="7.10.terraform与自动化.html">
            
                    
                        <b>1.8.10.</b>
                    
                    Terraform 与自动化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="8.CloudPosse最佳实践.html">
            
                <a href="8.CloudPosse最佳实践.html">
            
                    
                        <b>1.9.</b>
                    
                    来自CloudPosse的Terraform最佳实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="9.后记.html">
            
                <a href="9.后记.html">
            
                    
                        <b>1.10.</b>
                    
                    后记
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >状态管理</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#terraform-&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;"><b>1.3.2.1. </b>Terraform &#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;</a></li><ul><li><span class="title-icon "></span><a href="#&#x521D;&#x63A2;&#x72B6;&#x6001;&#x6587;&#x4EF6;"><b>1.3.2.1.1. </b>&#x521D;&#x63A2;&#x72B6;&#x6001;&#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x5B89;&#x5168;&#x8B66;&#x793A;&#x2014;&#x2014;-tfstate-&#x662F;&#x660E;&#x6587;&#x7684;"><b>1.3.2.1.2. </b>&#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x5B89;&#x5168;&#x8B66;&#x793A;&#x2014;&#x2014; tfstate &#x662F;&#x660E;&#x6587;&#x7684;</a></li><li><span class="title-icon "></span><a href="#&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x7684;-tfstate-&#x7BA1;&#x7406;&#x65B9;&#x6848;&#x2014;&#x2014;-backend"><b>1.3.2.1.3. </b>&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x7684; tfstate &#x7BA1;&#x7406;&#x65B9;&#x6848;&#x2014;&#x2014; Backend</a></li><li><span class="title-icon "></span><a href="#consul&#x7B80;&#x4ECB;&#x4EE5;&#x53CA;&#x5B89;&#x88C5;"><b>1.3.2.1.4. </b>Consul&#x7B80;&#x4ECB;&#x4EE5;&#x53CA;&#x5B89;&#x88C5;</a></li><li><span class="title-icon "></span><a href="#&#x4F7F;&#x7528;-backend"><b>1.3.2.1.5. </b>&#x4F7F;&#x7528; Backend</a></li><li><span class="title-icon "></span><a href="#&#x89C2;&#x5BDF;&#x9501;&#x6587;&#x4EF6;"><b>1.3.2.1.6. </b>&#x89C2;&#x5BDF;&#x9501;&#x6587;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#backend-&#x914D;&#x7F6E;&#x7684;&#x52A8;&#x6001;&#x8D4B;&#x503C;"><b>1.3.2.1.7. </b>Backend &#x914D;&#x7F6E;&#x7684;&#x52A8;&#x6001;&#x8D4B;&#x503C;</a></li><li><span class="title-icon "></span><a href="#backend-&#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;"><b>1.3.2.1.8. </b>Backend &#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;</a></li><li><span class="title-icon "></span><a href="#&#x72B6;&#x6001;&#x7684;&#x9694;&#x79BB;&#x5B58;&#x50A8;"><b>1.3.2.1.9. </b>&#x72B6;&#x6001;&#x7684;&#x9694;&#x79BB;&#x5B58;&#x50A8;</a></li><li><span class="title-icon "></span><a href="#&#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x79CD;&#x9694;&#x79BB;"><b>1.3.2.1.10. </b>&#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x79CD;&#x9694;&#x79BB;</a></li></ul></ul></div><a href="#terraform-&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="terraform-&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;"><a name="terraform-&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;" class="anchor-navigation-ex-anchor" href="#terraform-&#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1. Terraform &#x57FA;&#x7840;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;</h1>
<p>&#x6211;&#x4EEC;&#x5728;&#x7B2C;&#x4E00;&#x7AE0;&#x7684;&#x672B;&#x5C3E;&#x63D0;&#x8FC7;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x6210;&#x529F;&#x5730;&#x6267;&#x884C;&#x4E86;&#x4E00;&#x6B21; <code>terraform apply</code>&#xFF0C;&#x521B;&#x5EFA;&#x4E86;&#x671F;&#x671B;&#x7684;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x4EE5;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x5982;&#x679C;&#x518D;&#x6B21;&#x6267;&#x884C; <code>terraform apply</code>&#xFF0C;&#x751F;&#x6210;&#x7684;&#x65B0;&#x7684;&#x6267;&#x884C;&#x8BA1;&#x5212;&#x5C06;&#x4E0D;&#x4F1A;&#x5305;&#x542B;&#x4EFB;&#x4F55;&#x53D8;&#x66F4;&#xFF0C;Terraform &#x4F1A;&#x8BB0;&#x4F4F;&#x5F53;&#x524D;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x5E76;&#x5C06;&#x4E4B;&#x4E0E;&#x4EE3;&#x7801;&#x6240;&#x63CF;&#x8FF0;&#x7684;&#x671F;&#x671B;&#x72B6;&#x6001;&#x8FDB;&#x884C;&#x6BD4;&#x5BF9;&#x3002;&#x7B2C;&#x4E8C;&#x6B21; apply &#x65F6;&#xFF0C;&#x56E0;&#x4E3A;&#x5F53;&#x524D;&#x72B6;&#x6001;&#x5DF2;&#x7ECF;&#x4E0E;&#x4EE3;&#x7801;&#x63CF;&#x8FF0;&#x7684;&#x72B6;&#x6001;&#x4E00;&#x81F4;&#x4E86;&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x7A7A;&#x7684;&#x6267;&#x884C;&#x8BA1;&#x5212;&#x3002;</p>
<h2 id="&#x521D;&#x63A2;&#x72B6;&#x6001;&#x6587;&#x4EF6;"><a name="&#x521D;&#x63A2;&#x72B6;&#x6001;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x521D;&#x63A2;&#x72B6;&#x6001;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.1. &#x521D;&#x63A2;&#x72B6;&#x6001;&#x6587;&#x4EF6;</h2>
<p>&#x5728;&#x8FD9;&#x91CC;&#xFF0C;Terraform &#x5F15;&#x5165;&#x4E86;&#x4E00;&#x4E2A;&#x72EC;&#x7279;&#x7684;&#x6982;&#x5FF5;&#x2014;&#x2014;&#x72B6;&#x6001;&#x7BA1;&#x7406;&#xFF0C;&#x8FD9;&#x662F; Ansible &#x7B49;&#x914D;&#x7F6E;&#x7BA1;&#x7406;&#x5DE5;&#x5177;&#x6216;&#x662F;&#x81EA;&#x7814;&#x5DE5;&#x5177;&#x8C03;&#x7528; SDK &#x64CD;&#x4F5C;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x7684;&#x65B9;&#x6848;&#x6240;&#x6CA1;&#x6709;&#x7684;&#x3002;&#x7B80;&#x5355;&#x6765;&#x8BF4;&#xFF0C;Terraform &#x5C06;&#x6BCF;&#x6B21;&#x6267;&#x884C;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x53D8;&#x66F4;&#x64CD;&#x4F5C;&#x65F6;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x4FDD;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#x4F1A;&#x4FDD;&#x5B58;&#x5728;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>terraform.tfstate</code> &#x6587;&#x4EF6;&#x91CC;&#x3002;&#x4F8B;&#x5982;&#x6211;&#x4EEC;&#x4E4B;&#x524D;&#x5728;&#x4F7F;&#x7528; LocalStack &#x6A21;&#x62DF;&#x73AF;&#x5883;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#x58F0;&#x660E;&#x4E00;&#x4E2A; <code>data</code> &#x548C;&#x4E00;&#x4E2A; <code>resource</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">terraform</span> <span class="token punctuation">{</span>
  <span class="token keyword">required_providers</span> <span class="token punctuation">{</span>
    <span class="token property">aws</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
      <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;hashicorp/aws&quot;</span>
      <span class="token property">version</span> <span class="token punctuation">=</span> <span class="token string">&quot;~&gt;5.0&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">provider<span class="token type variable"> &quot;aws&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">access_key</span>                  <span class="token punctuation">=</span> <span class="token string">&quot;test&quot;</span>
  <span class="token property">secret_key</span>                  <span class="token punctuation">=</span> <span class="token string">&quot;test&quot;</span>
  <span class="token property">region</span>                      <span class="token punctuation">=</span> <span class="token string">&quot;us-east-1&quot;</span>
  <span class="token property">s3_use_path_style</span>           <span class="token punctuation">=</span> <span class="token boolean">false</span>
  <span class="token property">skip_credentials_validation</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>
  <span class="token property">skip_metadata_api_check</span>     <span class="token punctuation">=</span> <span class="token boolean">true</span>
  <span class="token property">skip_requesting_account_id</span>  <span class="token punctuation">=</span> <span class="token boolean">true</span>

  <span class="token keyword">endpoints</span> <span class="token punctuation">{</span>
    <span class="token property">apigateway</span>     <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">apigatewayv2</span>   <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">cloudformation</span> <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">cloudwatch</span>     <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">dynamodb</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ec2</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">es</span>             <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">elasticache</span>    <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">firehose</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">iam</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">kinesis</span>        <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">lambda</span>         <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">rds</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">redshift</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">route53</span>        <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">s3</span>             <span class="token punctuation">=</span> <span class="token string">&quot;http://s3.localhost.localstack.cloud:4566&quot;</span>
    <span class="token property">secretsmanager</span> <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ses</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sns</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sqs</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ssm</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">stepfunctions</span>  <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sts</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">data <span class="token type variable">&quot;aws_ami&quot;</span></span> <span class="token string">&quot;ubuntu&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">most_recent</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>

  <span class="token keyword">filter</span> <span class="token punctuation">{</span>
    <span class="token property">name</span>   <span class="token punctuation">=</span> <span class="token string">&quot;name&quot;</span>
    <span class="token property">values</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727&quot;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">filter</span> <span class="token punctuation">{</span>
    <span class="token property">name</span>   <span class="token punctuation">=</span> <span class="token string">&quot;virtualization-type&quot;</span>
    <span class="token property">values</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;hvm&quot;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>

  <span class="token property">owners</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;099720109477&quot;</span><span class="token punctuation">]</span> <span class="token comment"># Canonical</span>
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;web&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">ami</span>           <span class="token punctuation">=</span> data.aws_ami.ubuntu.id
  <span class="token property">instance_type</span> <span class="token punctuation">=</span> <span class="token string">&quot;t3.micro&quot;</span>

  <span class="token property">tags</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
    <span class="token property">Name</span> <span class="token punctuation">=</span> <span class="token string">&quot;HelloWorld&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4F7F;&#x7528; <code>terraform apply</code> &#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230; <code>terraform.tfstate</code> &#x7684;&#x5185;&#x5BB9;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
  <span class="token property">&quot;terraform_version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1.7.3&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;serial&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  <span class="token property">&quot;lineage&quot;</span><span class="token operator">:</span> <span class="token string">&quot;159018e2-63f4-2dfa-ce0d-873a37a1e0a7&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;outputs&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;resources&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;mode&quot;</span><span class="token operator">:</span> <span class="token string">&quot;data&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;aws_ami&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ubuntu&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;provider&quot;</span><span class="token operator">:</span> <span class="token string">&quot;provider[\&quot;registry.terraform.io/hashicorp/aws\&quot;]&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;instances&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span>
          <span class="token property">&quot;schema_version&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
          <span class="token property">&quot;attributes&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;architecture&quot;</span><span class="token operator">:</span> <span class="token string">&quot;x86_64&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;arn&quot;</span><span class="token operator">:</span> <span class="token string">&quot;arn:aws:ec2:us-east-1::image/ami-1e749f67&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;block_device_mappings&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
              <span class="token punctuation">{</span>
                <span class="token property">&quot;device_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/dev/sda1&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;ebs&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
                  <span class="token property">&quot;delete_on_termination&quot;</span><span class="token operator">:</span> <span class="token string">&quot;false&quot;</span><span class="token punctuation">,</span>
                  <span class="token property">&quot;encrypted&quot;</span><span class="token operator">:</span> <span class="token string">&quot;false&quot;</span><span class="token punctuation">,</span>
                  <span class="token property">&quot;iops&quot;</span><span class="token operator">:</span> <span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span>
                  <span class="token property">&quot;snapshot_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;snap-15bd5527&quot;</span><span class="token punctuation">,</span>
                  <span class="token property">&quot;throughput&quot;</span><span class="token operator">:</span> <span class="token string">&quot;0&quot;</span><span class="token punctuation">,</span>
                  <span class="token property">&quot;volume_size&quot;</span><span class="token operator">:</span> <span class="token string">&quot;15&quot;</span><span class="token punctuation">,</span>
                  <span class="token property">&quot;volume_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;standard&quot;</span>
                <span class="token punctuation">}</span><span class="token punctuation">,</span>
                <span class="token property">&quot;no_device&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;virtual_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span>
              <span class="token punctuation">}</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;boot_mode&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;creation_date&quot;</span><span class="token operator">:</span> <span class="token string">&quot;2024-02-20T13:52:42.000Z&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;deprecation_time&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;description&quot;</span><span class="token operator">:</span> <span class="token string">&quot;Canonical, Ubuntu, 14.04 LTS, amd64 trusty image build on 2017-07-27&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ena_support&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;executable_users&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;filter&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
              <span class="token punctuation">{</span>
                <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;name&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;values&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                  <span class="token string">&quot;ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727&quot;</span>
                <span class="token punctuation">]</span>
              <span class="token punctuation">}</span><span class="token punctuation">,</span>
              <span class="token punctuation">{</span>
                <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;virtualization-type&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;values&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                  <span class="token string">&quot;hvm&quot;</span>
                <span class="token punctuation">]</span>
              <span class="token punctuation">}</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;hypervisor&quot;</span><span class="token operator">:</span> <span class="token string">&quot;xen&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ami-1e749f67&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;image_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ami-1e749f67&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;image_location&quot;</span><span class="token operator">:</span> <span class="token string">&quot;amazon/getting-started&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;image_owner_alias&quot;</span><span class="token operator">:</span> <span class="token string">&quot;amazon&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;image_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;machine&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;imds_support&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;include_deprecated&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;kernel_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;None&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;most_recent&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
            <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;name_regex&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;owner_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;099720109477&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;owners&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
              <span class="token string">&quot;099720109477&quot;</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;platform&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;platform_details&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;product_codes&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ramdisk_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ari-1a2b3c4d&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;root_device_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/dev/sda1&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;root_device_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ebs&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;root_snapshot_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;snap-15bd5527&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;sriov_net_support&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;state&quot;</span><span class="token operator">:</span> <span class="token string">&quot;available&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;state_reason&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
              <span class="token property">&quot;code&quot;</span><span class="token operator">:</span> <span class="token string">&quot;UNSET&quot;</span><span class="token punctuation">,</span>
              <span class="token property">&quot;message&quot;</span><span class="token operator">:</span> <span class="token string">&quot;UNSET&quot;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token property">&quot;tags&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token property">&quot;timeouts&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;tpm_support&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;usage_operation&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;virtualization_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;hvm&quot;</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token property">&quot;sensitive_attributes&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">]</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;mode&quot;</span><span class="token operator">:</span> <span class="token string">&quot;managed&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;aws_instance&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;web&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;provider&quot;</span><span class="token operator">:</span> <span class="token string">&quot;provider[\&quot;registry.terraform.io/hashicorp/aws\&quot;]&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;instances&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span>
          <span class="token property">&quot;schema_version&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
          <span class="token property">&quot;attributes&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;ami&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ami-1e749f67&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;arn&quot;</span><span class="token operator">:</span> <span class="token string">&quot;arn:aws:ec2:us-east-1::instance/i-288a34165ed2ad2f7&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;associate_public_ip_address&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
            <span class="token property">&quot;availability_zone&quot;</span><span class="token operator">:</span> <span class="token string">&quot;us-east-1a&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;capacity_reservation_specification&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;cpu_core_count&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;cpu_options&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;cpu_threads_per_core&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;credit_specification&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;disable_api_stop&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;disable_api_termination&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ebs_block_device&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ebs_optimized&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;enclave_options&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ephemeral_block_device&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;get_password_data&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;hibernation&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;host_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;host_resource_group_arn&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;iam_instance_profile&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;i-288a34165ed2ad2f7&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;instance_initiated_shutdown_behavior&quot;</span><span class="token operator">:</span> <span class="token string">&quot;stop&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;instance_lifecycle&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;instance_market_options&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;instance_state&quot;</span><span class="token operator">:</span> <span class="token string">&quot;running&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;instance_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;t3.micro&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ipv6_address_count&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ipv6_addresses&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;key_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;launch_template&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;maintenance_options&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;metadata_options&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;monitoring&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;network_interface&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;outpost_arn&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;password_data&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;placement_group&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;placement_partition_number&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
            <span class="token property">&quot;primary_network_interface_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;eni-68899bf6&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;private_dns&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ip-10-13-239-41.ec2.internal&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;private_dns_name_options&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;private_ip&quot;</span><span class="token operator">:</span> <span class="token string">&quot;10.13.239.41&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public_dns&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ec2-54-214-132-221.compute-1.amazonaws.com&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public_ip&quot;</span><span class="token operator">:</span> <span class="token string">&quot;54.214.132.221&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;root_block_device&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
              <span class="token punctuation">{</span>
                <span class="token property">&quot;delete_on_termination&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
                <span class="token property">&quot;device_name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;/dev/sda1&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;encrypted&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
                <span class="token property">&quot;iops&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
                <span class="token property">&quot;kms_key_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;tags&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
                <span class="token property">&quot;throughput&quot;</span><span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>
                <span class="token property">&quot;volume_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;vol-6dde834f&quot;</span><span class="token punctuation">,</span>
                <span class="token property">&quot;volume_size&quot;</span><span class="token operator">:</span> <span class="token number">8</span><span class="token punctuation">,</span>
                <span class="token property">&quot;volume_type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;gp2&quot;</span>
              <span class="token punctuation">}</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;secondary_private_ips&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;security_groups&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token property">&quot;source_dest_check&quot;</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
            <span class="token property">&quot;spot_instance_request_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;subnet_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;subnet-dbb4c2f9&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;tags&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
              <span class="token property">&quot;Name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;HelloWorld&quot;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token property">&quot;tags_all&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
              <span class="token property">&quot;Name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;HelloWorld&quot;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token property">&quot;tenancy&quot;</span><span class="token operator">:</span> <span class="token string">&quot;default&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;timeouts&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;user_data&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;user_data_base64&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;user_data_replace_on_change&quot;</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
            <span class="token property">&quot;volume_tags&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span><span class="token punctuation">,</span>
            <span class="token property">&quot;vpc_security_group_ids&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token property">&quot;sensitive_attributes&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
          <span class="token property">&quot;private&quot;</span><span class="token operator">:</span> <span class="token string">&quot;eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMCwidXBkYXRlIjo2MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjEifQ==&quot;</span><span class="token punctuation">,</span>
          <span class="token property">&quot;dependencies&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
            <span class="token string">&quot;data.aws_ami.ubuntu&quot;</span>
          <span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token property">&quot;check_results&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x67E5;&#x8BE2;&#x5230;&#x7684; <code>data</code> &#x4EE5;&#x53CA;&#x521B;&#x5EFA;&#x7684; <code>resource</code> &#x4FE1;&#x606F;&#x90FD;&#x88AB;&#x4EE5; json &#x683C;&#x5F0F;&#x4FDD;&#x5B58;&#x5728; <code>tfstate</code> &#x6587;&#x4EF6;&#x91CC;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x524D;&#x9762;&#x5DF2;&#x7ECF;&#x8BF4;&#x8FC7;&#xFF0C;&#x7531;&#x4E8E; <code>tfstate</code> &#x6587;&#x4EF6;&#x7684;&#x5B58;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x5728; <code>terraform apply</code> &#x4E4B;&#x540E;&#x7ACB;&#x5373;&#x518D;&#x6B21; apply &#x662F;&#x4E0D;&#x4F1A;&#x6267;&#x884C;&#x4EFB;&#x4F55;&#x53D8;&#x66F4;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5220;&#x9664;&#x4E86;&#x8FD9;&#x4E2A; <code>tfstate</code> &#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x6267;&#x884C; apply &#x4F1A;&#x53D1;&#x751F;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;Terraform &#x8BFB;&#x53D6;&#x4E0D;&#x5230; <code>tfstate</code> &#x6587;&#x4EF6;&#xFF0C;&#x4F1A;&#x8BA4;&#x4E3A;&#x8FD9;&#x662F;&#x6211;&#x4EEC;&#x7B2C;&#x4E00;&#x6B21;&#x521B;&#x5EFA;&#x8FD9;&#x7EC4;&#x8D44;&#x6E90;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x4F1A;&#x518D;&#x4E00;&#x6B21;&#x521B;&#x5EFA;&#x4EE3;&#x7801;&#x4E2D;&#x63CF;&#x8FF0;&#x7684;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x3002;&#x66F4;&#x52A0;&#x9EBB;&#x70E6;&#x7684;&#x662F;&#xFF0C;&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x524D;&#x4E00;&#x6B21;&#x521B;&#x5EFA;&#x7684;&#x8D44;&#x6E90;&#x6240;&#x5BF9;&#x5E94;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x88AB;&#x6211;&#x4EEC;&#x5220;&#x9664;&#x4E86;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x518D;&#x4E5F;&#x65E0;&#x6CD5;&#x901A;&#x8FC7;&#x6267;&#x884C; <code>terraform destroy</code> &#x6765;&#x9500;&#x6BC1;&#x548C;&#x56DE;&#x6536;&#x8FD9;&#x4E9B;&#x8D44;&#x6E90;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x4EA7;&#x751F;&#x4E86;&#x8D44;&#x6E90;&#x6CC4;&#x6F0F;&#x3002;&#x6240;&#x4EE5;&#x59A5;&#x5584;&#x4FDD;&#x5B58;&#x8FD9;&#x4E2A;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x662F;&#x975E;&#x5E38;&#x91CD;&#x8981;&#x7684;&#x3002;</p>
<p>&#x53E6;&#x5916;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x5BF9; Terraform &#x7684;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4E86;&#x4E00;&#x4E9B;&#x4FEE;&#x6539;&#xFF0C;&#x5BFC;&#x81F4;&#x751F;&#x6210;&#x7684;&#x6267;&#x884C;&#x8BA1;&#x5212;&#x5C06;&#x4F1A;&#x6539;&#x53D8;&#x72B6;&#x6001;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x5B9E;&#x9645;&#x6267;&#x884C;&#x53D8;&#x66F4;&#x4E4B;&#x524D;&#xFF0C;Terraform &#x4F1A;&#x590D;&#x5236;&#x4E00;&#x4EFD;&#x5F53;&#x524D;&#x7684; <code>tfstate</code> &#x6587;&#x4EF6;&#x5230;&#x540C;&#x8DEF;&#x5F84;&#x4E0B;&#x7684; <code>terraform.tfstate.backup</code> &#x4E2D;&#xFF0C;&#x4EE5;&#x9632;&#x6B62;&#x7531;&#x4E8E;&#x5404;&#x79CD;&#x610F;&#x5916;&#x5BFC;&#x81F4;&#x7684; <code>tfstate</code> &#x635F;&#x6BC1;&#x3002;</p>
<p>&#x5728; Terraform &#x53D1;&#x5C55;&#x7684;&#x6781;&#x65E9;&#x671F;&#xFF0C;HashiCorp &#x66FE;&#x7ECF;&#x5C1D;&#x8BD5;&#x8FC7;&#x65E0;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x7684;&#x65B9;&#x6848;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x5728;&#x6267;&#x884C; Terraform &#x53D8;&#x66F4;&#x8BA1;&#x5212;&#x65F6;&#xFF0C;&#x7ED9;&#x6240;&#x6709;&#x6D89;&#x53CA;&#x5230;&#x7684;&#x8D44;&#x6E90;&#x90FD;&#x6253;&#x4E0A;&#x7279;&#x5B9A;&#x7684; tag&#xFF0C;&#x5728;&#x4E0B;&#x6B21;&#x6267;&#x884C;&#x53D8;&#x66F4;&#x65F6;&#xFF0C;&#x5148;&#x901A;&#x8FC7; tag &#x8BFB;&#x53D6;&#x76F8;&#x5173;&#x8D44;&#x6E90;&#x6765;&#x91CD;&#x5EFA;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;&#x4F46;&#x56E0;&#x4E3A;&#x5E76;&#x4E0D;&#x662F;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x90FD;&#x652F;&#x6301;&#x6253; tag&#xFF0C;&#x4E5F;&#x4E0D;&#x662F;&#x6240;&#x6709;&#x516C;&#x6709;&#x4E91;&#x90FD;&#x652F;&#x6301;&#x591A; tag&#xFF0C;&#x6240;&#x4EE5; Terraform &#x6700;&#x7EC8;&#x51B3;&#x5B9A;&#x7528;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x65B9;&#x6848;&#x3002;</p>
<p>&#x8FD8;&#x6709;&#x4E00;&#x70B9;&#xFF0C;HashiCorp &#x5B98;&#x65B9;&#x4ECE;&#x672A;&#x516C;&#x5F00;&#x8FC7; <code>tfstate</code> &#x7684;&#x683C;&#x5F0F;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;HashiCorp &#x4FDD;&#x7559;&#x968F;&#x65F6;&#x4FEE;&#x6539; <code>tfstate</code> &#x683C;&#x5F0F;&#x7684;&#x6743;&#x529B;&#x3002;&#x6240;&#x4EE5;&#x4E0D;&#x8981;&#x8BD5;&#x56FE;&#x624B;&#x52A8;&#x6216;&#x662F;&#x7528;&#x81EA;&#x7814;&#x4EE3;&#x7801;&#x53BB;&#x4FEE;&#x6539; <code>tfstate</code>&#xFF0C;Terraform &#x547D;&#x4EE4;&#x884C;&#x5DE5;&#x5177;&#x63D0;&#x4F9B;&#x4E86;&#x76F8;&#x5173;&#x7684;&#x6307;&#x4EE4;(&#x6211;&#x4EEC;&#x540E;&#x7EED;&#x4F1A;&#x4ECB;&#x7ECD;&#x5230;)&#xFF0C;&#x8BF7;&#x786E;&#x4FDD;&#x53EA;&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x884C;&#x7684;&#x6307;&#x4EE4;&#x64CD;&#x4F5C;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x3002;</p>
<h2 id="&#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x5B89;&#x5168;&#x8B66;&#x793A;&#x2014;&#x2014;-tfstate-&#x662F;&#x660E;&#x6587;&#x7684;"><a name="&#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x5B89;&#x5168;&#x8B66;&#x793A;&#x2014;&#x2014;-tfstate-&#x662F;&#x660E;&#x6587;&#x7684;" class="anchor-navigation-ex-anchor" href="#&#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x5B89;&#x5168;&#x8B66;&#x793A;&#x2014;&#x2014;-tfstate-&#x662F;&#x660E;&#x6587;&#x7684;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.2. &#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x5B89;&#x5168;&#x8B66;&#x793A;&#x2014;&#x2014; tfstate &#x662F;&#x660E;&#x6587;&#x7684;</h2>
<p>&#x5173;&#x4E8E; Terraform &#x72B6;&#x6001;&#xFF0C;&#x8FD8;&#x6709;&#x6781;&#x5176;&#x91CD;&#x8981;&#x7684;&#x4E8B;&#xFF0C;&#x6240;&#x6709;&#x8003;&#x8651;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4F7F;&#x7528; Terraform &#x7684;&#x4EBA;&#x90FD;&#x5FC5;&#x987B;&#x683C;&#x5916;&#x5C0F;&#x5FC3;&#x5E76;&#x518D;&#x4E09;&#x8B66;&#x60D5;&#xFF1A;Terraform &#x7684;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x662F;&#x660E;&#x6587;&#x7684;&#xFF0C;&#x8FD9;&#x5C31;&#x610F;&#x5473;&#x7740;&#x4EE3;&#x7801;&#x4E2D;&#x6240;&#x4F7F;&#x7528;&#x7684;&#x4E00;&#x5207;&#x673A;&#x5BC6;&#x4FE1;&#x606F;&#x90FD;&#x5C06;&#x4EE5;&#x660E;&#x6587;&#x7684;&#x5F62;&#x5F0F;&#x4FDD;&#x5B58;&#x5728;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x91CC;&#x3002;&#x4F8B;&#x5982;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x79C1;&#x94A5;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">resource <span class="token type variable">&quot;tls_private_key&quot;</span></span> <span class="token string">&quot;example&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">algorithm</span> <span class="token punctuation">=</span> <span class="token string">&quot;RSA&quot;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x6267;&#x884C;&#x4E86;<code>terraform apply</code>&#x540E;&#x6211;&#x4EEC;&#x89C2;&#x5BDF; <code>tfstate</code> &#x6587;&#x4EF6;&#x4E2D;&#x76F8;&#x5173;&#x6BB5;&#x843D;&#xFF1A;</p>
<pre class="language-"><code class="lang-json"><span class="token punctuation">{</span>
  <span class="token property">&quot;version&quot;</span><span class="token operator">:</span> <span class="token number">4</span><span class="token punctuation">,</span>
  <span class="token property">&quot;terraform_version&quot;</span><span class="token operator">:</span> <span class="token string">&quot;1.7.3&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;serial&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  <span class="token property">&quot;lineage&quot;</span><span class="token operator">:</span> <span class="token string">&quot;dec42d6b-d61f-30b3-0b83-d5d8881c29ea&quot;</span><span class="token punctuation">,</span>
  <span class="token property">&quot;outputs&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token property">&quot;resources&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token property">&quot;mode&quot;</span><span class="token operator">:</span> <span class="token string">&quot;managed&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;tls_private_key&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;name&quot;</span><span class="token operator">:</span> <span class="token string">&quot;example&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;provider&quot;</span><span class="token operator">:</span> <span class="token string">&quot;provider[\&quot;registry.terraform.io/hashicorp/tls\&quot;]&quot;</span><span class="token punctuation">,</span>
      <span class="token property">&quot;instances&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
        <span class="token punctuation">{</span>
          <span class="token property">&quot;schema_version&quot;</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
          <span class="token property">&quot;attributes&quot;</span><span class="token operator">:</span> <span class="token punctuation">{</span>
            <span class="token property">&quot;algorithm&quot;</span><span class="token operator">:</span> <span class="token string">&quot;RSA&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;ecdsa_curve&quot;</span><span class="token operator">:</span> <span class="token string">&quot;P224&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;d47d1465586d25322bb8ca16029fe4fb2ec001e0&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;private_key_openssh&quot;</span><span class="token operator">:</span> <span class="token string">&quot;-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdz\nc2gtcnNhAAAAAwEAAQAAAQEAsdD9sJ/L5m8cRB19V20HA9BIqZwnT3id5JoMNUuW\nYn4sJTWHa/JHkQ5akrWH50aIdzQrQneIZXJyx1OMlqKbVxAc2+u/8qd2m2GrsWKZ\neqQcpNT7v76QowDcvdggad3Tezn3XU/eBukVj9i+lnN1ofyQzVEQAdvW8TpRdUL5\nb/bIsz1RzGWzUrWD8XTFLf2RuvvzhgBViuuWI0ns3WQMpa6Dcu+nWfGLCl26Wlph\nNmoUAv8wCay7KoynG58pJW+uqYA7lTx4tNMLhIW7rM4roYbXctkCi03PcW3x25O8\nyKSzYIi5xH7CQ7ggwXzcx4r06NXkaE9/LHuBSFJcIMvH8QAAA7jnMVXy5zFV8gAA\nAAdzc2gtcnNhAAABAQCx0P2wn8vmbxxEHX1XbQcD0EipnCdPeJ3kmgw1S5Zifiwl\nNYdr8keRDlqStYfnRoh3NCtCd4hlcnLHU4yWoptXEBzb67/yp3abYauxYpl6pByk\n1Pu/vpCjANy92CBp3dN7OfddT94G6RWP2L6Wc3Wh/JDNURAB29bxOlF1Qvlv9siz\nPVHMZbNStYPxdMUt/ZG6+/OGAFWK65YjSezdZAylroNy76dZ8YsKXbpaWmE2ahQC\n/zAJrLsqjKcbnyklb66pgDuVPHi00wuEhbusziuhhtdy2QKLTc9xbfHbk7zIpLNg\niLnEfsJDuCDBfNzHivTo1eRoT38se4FIUlwgy8fxAAAAAwEAAQAAAQEAleLv5ZFd\nY9mm/vfIrwg1UI6ioW4CaOfoWElOHyKfGlj2x0qu41wv3WM3D9G7REVdRPYRvQ5b\nSABIJiMUL+nTfXkUioDXpShqPyH+gyD09L8fcgYiS4fMDcrtR43GDNcyq/25uMtZ\nAYQ6a62tQc8Dik8GlDtPffGc5mxdO7X/4tLAObBPqO+lvGX2K/2hV2ql/a4fBVXR\nOMPc9A0eva2exifZyFo9vT9CCcW4iNY2BHY2hXAPI1gFpBnmnY2twFof4EvX6tfZ\nGjt20QCqTi41P8Obrfqi108zRAKtjJFeezNY+diVvxZaCDb/7ceFbFUrXq9u2UVD\nExn9joOLTJTEwQAAAIEAgOQ/mjRousgSenXW2nE2aq0m7oKQzhsF/8k5UPj6mym1\nvwUyC2gglTIOGVkUpj91L/Fh2nCuX5BLyzzIee0twRvT1Kj11BU6UoElStpR/JEC\n7trKWJrBddphBWHAuVcU5AQQPwI/9sg27q/9y16WTIQAJzx8GwGcDbgZj8/LbB4A\nAACBAMpVcX+2smqt8T9mbwU7e7ZaCQM0c3/7F2S2Z26Zl16k+8WPr6+CyJd3d2s2\nQkrmqVKJzDqPYidU0EmaNOrqytvUTUDK9KJgKsJuNC9ZbODqTCMA03ntr+hVcfdt\nd9F5fxyBJSrzpAhUQKadHs8jtAa1ENAhPmwKzvcJ51Gp4R3ZAAAAgQDg+s4nk926\njuLQGlweOi2HY6eeMQF8MOnXEhM8P7ErdRR73ql7GlhBNoGzuI6YTaqjLXBGNetj\nm4iziPLapbqBXSeia3y1JU71e1M+J342CxQwZRKTI9G/AB2AzspB4VfjAT9ZYJM1\nSFH7cDTejcrkfWko8TqyRLwtTPDa7Xlz2QAAAAAB\n-----END OPENSSH PRIVATE KEY-----\n&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;private_key_pem&quot;</span><span class="token operator">:</span> <span class="token string">&quot;-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAsdD9sJ/L5m8cRB19V20HA9BIqZwnT3id5JoMNUuWYn4sJTWH\na/JHkQ5akrWH50aIdzQrQneIZXJyx1OMlqKbVxAc2+u/8qd2m2GrsWKZeqQcpNT7\nv76QowDcvdggad3Tezn3XU/eBukVj9i+lnN1ofyQzVEQAdvW8TpRdUL5b/bIsz1R\nzGWzUrWD8XTFLf2RuvvzhgBViuuWI0ns3WQMpa6Dcu+nWfGLCl26WlphNmoUAv8w\nCay7KoynG58pJW+uqYA7lTx4tNMLhIW7rM4roYbXctkCi03PcW3x25O8yKSzYIi5\nxH7CQ7ggwXzcx4r06NXkaE9/LHuBSFJcIMvH8QIDAQABAoIBAQCV4u/lkV1j2ab+\n98ivCDVQjqKhbgJo5+hYSU4fIp8aWPbHSq7jXC/dYzcP0btERV1E9hG9DltIAEgm\nIxQv6dN9eRSKgNelKGo/If6DIPT0vx9yBiJLh8wNyu1HjcYM1zKr/bm4y1kBhDpr\nra1BzwOKTwaUO0998ZzmbF07tf/i0sA5sE+o76W8ZfYr/aFXaqX9rh8FVdE4w9z0\nDR69rZ7GJ9nIWj29P0IJxbiI1jYEdjaFcA8jWAWkGeadja3AWh/gS9fq19kaO3bR\nAKpOLjU/w5ut+qLXTzNEAq2MkV57M1j52JW/FloINv/tx4VsVSter27ZRUMTGf2O\ng4tMlMTBAoGBAMpVcX+2smqt8T9mbwU7e7ZaCQM0c3/7F2S2Z26Zl16k+8WPr6+C\nyJd3d2s2QkrmqVKJzDqPYidU0EmaNOrqytvUTUDK9KJgKsJuNC9ZbODqTCMA03nt\nr+hVcfdtd9F5fxyBJSrzpAhUQKadHs8jtAa1ENAhPmwKzvcJ51Gp4R3ZAoGBAOD6\nzieT3bqO4tAaXB46LYdjp54xAXww6dcSEzw/sSt1FHveqXsaWEE2gbO4jphNqqMt\ncEY162ObiLOI8tqluoFdJ6JrfLUlTvV7Uz4nfjYLFDBlEpMj0b8AHYDOykHhV+MB\nP1lgkzVIUftwNN6NyuR9aSjxOrJEvC1M8NrteXPZAoGAIQf/5nSh/e51ov8LAtSq\nJqPeMsq+TFdmg0eP7Stf3dCbVa5WZRW5v5h+Q19xRR8Q52udjrXXtUoQUuO83dkE\n0wx+rCQ1+cgvUtyA4nX741/8m/5Hh/E4tXo1h8o0NFtcV//xXGi4D7AJeenOnMxc\nWHf4zbGPqj29efEA9YEBQkkCgYABhG+DgNHMAk6xTJw2b/oCob9tp7L03XeWRb7v\ndxaAzodW1oeaFvFlbzKsvZ/okw2FkDbjolV2FIR1gYTxyJBbcv9jbwomRpwjt7M2\nBhopzyVRtjzL1UAC48NPLRXcH+Lx2v5MYgRcJaK36WfR4G7v35CoAAh/T0tdmtk9\nAMEC8QKBgQCA5D+aNGi6yBJ6ddbacTZqrSbugpDOGwX/yTlQ+PqbKbW/BTILaCCV\nMg4ZWRSmP3Uv8WHacK5fkEvLPMh57S3BG9PUqPXUFTpSgSVK2lH8kQLu2spYmsF1\n2mEFYcC5VxTkBBA/Aj/2yDbur/3LXpZMhAAnPHwbAZwNuBmPz8tsHg==\n-----END RSA PRIVATE KEY-----\n&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;private_key_pem_pkcs8&quot;</span><span class="token operator">:</span> <span class="token string">&quot;-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCx0P2wn8vmbxxE\nHX1XbQcD0EipnCdPeJ3kmgw1S5ZifiwlNYdr8keRDlqStYfnRoh3NCtCd4hlcnLH\nU4yWoptXEBzb67/yp3abYauxYpl6pByk1Pu/vpCjANy92CBp3dN7OfddT94G6RWP\n2L6Wc3Wh/JDNURAB29bxOlF1Qvlv9sizPVHMZbNStYPxdMUt/ZG6+/OGAFWK65Yj\nSezdZAylroNy76dZ8YsKXbpaWmE2ahQC/zAJrLsqjKcbnyklb66pgDuVPHi00wuE\nhbusziuhhtdy2QKLTc9xbfHbk7zIpLNgiLnEfsJDuCDBfNzHivTo1eRoT38se4FI\nUlwgy8fxAgMBAAECggEBAJXi7+WRXWPZpv73yK8INVCOoqFuAmjn6FhJTh8inxpY\n9sdKruNcL91jNw/Ru0RFXUT2Eb0OW0gASCYjFC/p0315FIqA16Uoaj8h/oMg9PS/\nH3IGIkuHzA3K7UeNxgzXMqv9ubjLWQGEOmutrUHPA4pPBpQ7T33xnOZsXTu1/+LS\nwDmwT6jvpbxl9iv9oVdqpf2uHwVV0TjD3PQNHr2tnsYn2chaPb0/QgnFuIjWNgR2\nNoVwDyNYBaQZ5p2NrcBaH+BL1+rX2Ro7dtEAqk4uNT/Dm636otdPM0QCrYyRXnsz\nWPnYlb8WWgg2/+3HhWxVK16vbtlFQxMZ/Y6Di0yUxMECgYEAylVxf7ayaq3xP2Zv\nBTt7tloJAzRzf/sXZLZnbpmXXqT7xY+vr4LIl3d3azZCSuapUonMOo9iJ1TQSZo0\n6urK29RNQMr0omAqwm40L1ls4OpMIwDTee2v6FVx92130Xl/HIElKvOkCFRApp0e\nzyO0BrUQ0CE+bArO9wnnUanhHdkCgYEA4PrOJ5Pduo7i0BpcHjoth2OnnjEBfDDp\n1xITPD+xK3UUe96pexpYQTaBs7iOmE2qoy1wRjXrY5uIs4jy2qW6gV0nomt8tSVO\n9XtTPid+NgsUMGUSkyPRvwAdgM7KQeFX4wE/WWCTNUhR+3A03o3K5H1pKPE6skS8\nLUzw2u15c9kCgYAhB//mdKH97nWi/wsC1Komo94yyr5MV2aDR4/tK1/d0JtVrlZl\nFbm/mH5DX3FFHxDna52Otde1ShBS47zd2QTTDH6sJDX5yC9S3IDidfvjX/yb/keH\n8Ti1ejWHyjQ0W1xX//FcaLgPsAl56c6czFxYd/jNsY+qPb158QD1gQFCSQKBgAGE\nb4OA0cwCTrFMnDZv+gKhv22nsvTdd5ZFvu93FoDOh1bWh5oW8WVvMqy9n+iTDYWQ\nNuOiVXYUhHWBhPHIkFty/2NvCiZGnCO3szYGGinPJVG2PMvVQALjw08tFdwf4vHa\n/kxiBFwlorfpZ9Hgbu/fkKgACH9PS12a2T0AwQLxAoGBAIDkP5o0aLrIEnp11tpx\nNmqtJu6CkM4bBf/JOVD4+psptb8FMgtoIJUyDhlZFKY/dS/xYdpwrl+QS8s8yHnt\nLcEb09So9dQVOlKBJUraUfyRAu7ayliawXXaYQVhwLlXFOQEED8CP/bINu6v/cte\nlkyEACc8fBsBnA24GY/Py2we\n-----END PRIVATE KEY-----\n&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public_key_fingerprint_md5&quot;</span><span class="token operator">:</span> <span class="token string">&quot;a9:cc:2d:0f:66:b9:a9:89:94:f1:da:8f:93:df:63:d5&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public_key_fingerprint_sha256&quot;</span><span class="token operator">:</span> <span class="token string">&quot;SHA256:ias4wauIC4J/zd/cVoXT6UUSUZLQXaxdpJfkGAfRDz0&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public_key_openssh&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCx0P2wn8vmbxxEHX1XbQcD0EipnCdPeJ3kmgw1S5ZifiwlNYdr8keRDlqStYfnRoh3NCtCd4hlcnLHU4yWoptXEBzb67/yp3abYauxYpl6pByk1Pu/vpCjANy92CBp3dN7OfddT94G6RWP2L6Wc3Wh/JDNURAB29bxOlF1Qvlv9sizPVHMZbNStYPxdMUt/ZG6+/OGAFWK65YjSezdZAylroNy76dZ8YsKXbpaWmE2ahQC/zAJrLsqjKcbnyklb66pgDuVPHi00wuEhbusziuhhtdy2QKLTc9xbfHbk7zIpLNgiLnEfsJDuCDBfNzHivTo1eRoT38se4FIUlwgy8fx\n&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;public_key_pem&quot;</span><span class="token operator">:</span> <span class="token string">&quot;-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdD9sJ/L5m8cRB19V20H\nA9BIqZwnT3id5JoMNUuWYn4sJTWHa/JHkQ5akrWH50aIdzQrQneIZXJyx1OMlqKb\nVxAc2+u/8qd2m2GrsWKZeqQcpNT7v76QowDcvdggad3Tezn3XU/eBukVj9i+lnN1\nofyQzVEQAdvW8TpRdUL5b/bIsz1RzGWzUrWD8XTFLf2RuvvzhgBViuuWI0ns3WQM\npa6Dcu+nWfGLCl26WlphNmoUAv8wCay7KoynG58pJW+uqYA7lTx4tNMLhIW7rM4r\noYbXctkCi03PcW3x25O8yKSzYIi5xH7CQ7ggwXzcx4r06NXkaE9/LHuBSFJcIMvH\n8QIDAQAB\n-----END PUBLIC KEY-----\n&quot;</span><span class="token punctuation">,</span>
            <span class="token property">&quot;rsa_bits&quot;</span><span class="token operator">:</span> <span class="token number">2048</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token property">&quot;sensitive_attributes&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token property">&quot;check_results&quot;</span><span class="token operator">:</span> <span class="token null keyword">null</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x4E0D;&#x5E94;&#x8BE5;&#x88AB;&#x7B2C;&#x4E09;&#x65B9;&#x77E5;&#x6653;&#x7684; <code>private_key_openssh</code>&#x3001;<code>private_key_pem</code> &#x548C; <code>private_key_pem_pkcs8</code> &#x662F;&#x4EE5;&#x660E;&#x6587;&#x5F62;&#x5F0F;&#x88AB;&#x5199;&#x5728; <code>tfstate</code> &#x6587;&#x4EF6;&#x91CC;&#x7684;&#x3002;&#x8FD9;&#x662F; Terraform &#x4ECE;&#x8BBE;&#x8BA1;&#x4E4B;&#x521D;&#x5C31;&#x786E;&#x5B9A;&#x7684;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x53EF;&#x89C1;&#x7684;&#x672A;&#x6765;&#x4E0D;&#x4F1A;&#x6709;&#x6539;&#x5584;&#x3002;&#x4E0D;&#x8BBA;&#x4F60;&#x662F;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x660E;&#x6587;&#x786C;&#x7F16;&#x7801;&#xFF0C;&#x8FD8;&#x662F;&#x4F7F;&#x7528;&#x53C2;&#x6570;(variable&#xFF0C;&#x6211;&#x4EEC;&#x4E4B;&#x540E;&#x7684;&#x7AE0;&#x8282;&#x4F1A;&#x4ECB;&#x7ECD;)&#xFF0C;&#x4EA6;&#x6216;&#x662F;&#x5999;&#x60F3;&#x5929;&#x5F00;&#x5730;&#x4F7F;&#x7528;&#x51FD;&#x6570;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x4ECE;&#x5916;&#x754C;&#x8BFB;&#x53D6;&#xFF0C;&#x90FD;&#x65E0;&#x6CD5;&#x6539;&#x53D8;&#x8FD9;&#x4E2A;&#x7ED3;&#x679C;&#x3002;</p>
<p>&#x89E3;&#x51B3;&#x4E4B;&#x9053;&#x6709;&#x4E24;&#x79CD;&#xFF0C;&#x4E00;&#x79CD;&#x662F;&#x4F7F;&#x7528; <a href="https://lonegunmanb.github.io/essential-vault/" target="_blank">Vault</a> &#x6216;&#x662F; <a href="https://aws.amazon.com/secrets-manager/" target="_blank">AWS Secret Manager</a> &#x8FD9;&#x6837;&#x7684;&#x52A8;&#x6001;&#x673A;&#x5BC6;&#x7BA1;&#x7406;&#x5DE5;&#x5177;&#x751F;&#x6210;&#x4E34;&#x65F6;&#x6709;&#x6548;&#x7684;&#x52A8;&#x6001;&#x673A;&#x5BC6;(&#x6BD4;&#x5982;&#x6709;&#x6548;&#x671F;&#x53EA;&#x6709; 5 &#x5206;&#x949F;&#xFF0C;&#x5373;&#x4F7F;&#x88AB;&#x4ED6;&#x4EBA;&#x8BFB;&#x53D6;&#x5230;&#xFF0C;&#x673A;&#x5BC6;&#x4E5F;&#x65E9;&#x5DF2;&#x5931;&#x6548;)&#xFF1B;&#x53E6;&#x4E00;&#x79CD;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x4E0B;&#x9762;&#x5C06;&#x8981;&#x4ECB;&#x7ECD;&#x7684; &#x2014;&#x2014; Terraform Backend&#x3002;</p>
<h2 id="&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x7684;-tfstate-&#x7BA1;&#x7406;&#x65B9;&#x6848;&#x2014;&#x2014;-backend"><a name="&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x7684;-tfstate-&#x7BA1;&#x7406;&#x65B9;&#x6848;&#x2014;&#x2014;-backend" class="anchor-navigation-ex-anchor" href="#&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x7684;-tfstate-&#x7BA1;&#x7406;&#x65B9;&#x6848;&#x2014;&#x2014;-backend"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.3. &#x751F;&#x4EA7;&#x73AF;&#x5883;&#x7684; tfstate &#x7BA1;&#x7406;&#x65B9;&#x6848;&#x2014;&#x2014; Backend</h2>
<p>&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#x6211;&#x4EEC;&#x7684; <code>tfstate</code> &#x6587;&#x4EF6;&#x662F;&#x4FDD;&#x5B58;&#x5728;&#x5F53;&#x524D;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x672C;&#x5730;&#x6587;&#x4EF6;&#xFF0C;&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x7684;&#x8BA1;&#x7B97;&#x673A;&#x635F;&#x574F;&#x4E86;&#xFF0C;&#x5BFC;&#x81F4;&#x6587;&#x4EF6;&#x4E22;&#x5931;&#xFF0C;&#x90A3;&#x4E48; <code>tfstate</code> &#x6587;&#x4EF6;&#x6240;&#x5BF9;&#x5E94;&#x7684;&#x8D44;&#x6E90;&#x90FD;&#x5C06;&#x65E0;&#x6CD5;&#x7BA1;&#x7406;&#xFF0C;&#x800C;&#x4EA7;&#x751F;&#x8D44;&#x6E90;&#x6CC4;&#x6F0F;&#x3002;</p>
<p>&#x53E6;&#x5916;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x662F;&#x4E00;&#x4E2A;&#x56E2;&#x961F;&#x5728;&#x4F7F;&#x7528; Terraform &#x7BA1;&#x7406;&#x4E00;&#x7EC4;&#x8D44;&#x6E90;&#xFF0C;&#x56E2;&#x961F;&#x6210;&#x5458;&#x4E4B;&#x95F4;&#x8981;&#x5982;&#x4F55;&#x5171;&#x4EAB;&#x8FD9;&#x4E2A;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#xFF1F;&#x80FD;&#x4E0D;&#x80FD;&#x628A; <code>tfstate</code> &#x6587;&#x4EF6;&#x7B7E;&#x5165;&#x6E90;&#x4EE3;&#x7801;&#x7BA1;&#x7406;&#x5DE5;&#x5177;&#x8FDB;&#x884C;&#x4FDD;&#x5B58;&#xFF1F;</p>
<p>&#x628A; <code>tfstate</code> &#x6587;&#x4EF6;&#x7B7E;&#x5165;&#x7BA1;&#x4EE3;&#x7801;&#x7BA1;&#x7406;&#x5DE5;&#x5177;&#x662F;&#x975E;&#x5E38;&#x9519;&#x8BEF;&#x7684;&#xFF0C;&#x8FD9;&#x5C31;&#x597D;&#x6BD4;&#x628A;&#x6570;&#x636E;&#x5E93;&#x7B7E;&#x5165;&#x4E86;&#x6E90;&#x4EE3;&#x7801;&#x7BA1;&#x7406;&#x5DE5;&#x5177;&#xFF0C;&#x5982;&#x679C;&#x4E24;&#x4E2A;&#x4EBA;&#x540C;&#x65F6;&#x7B7E;&#x51FA;&#x4E86;&#x540C;&#x4E00;&#x4EFD; <code>tfstate</code>&#xFF0C;&#x5E76;&#x4E14;&#x5BF9;&#x4EE3;&#x7801;&#x505A;&#x4E86;&#x4E0D;&#x540C;&#x7684;&#x4FEE;&#x6539;&#xFF0C;&#x53C8;&#x540C;&#x65F6; apply &#x4E86;&#xFF0C;&#x8FD9;&#x65F6;&#x60F3;&#x8981;&#x628A; <code>tfstate</code> &#x7B7E;&#x5165;&#x6E90;&#x7801;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x53EF;&#x80FD;&#x4F1A;&#x906D;&#x9047;&#x5230;&#x65E0;&#x6CD5;&#x89E3;&#x51B3;&#x7684;&#x51B2;&#x7A81;&#x3002;&#x51B5;&#x4E14;&#x5982;&#x679C;&#x4EE3;&#x7801;&#x4ED3;&#x5E93;&#x662F;&#x516C;&#x5F00;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x4FDD;&#x5B58;&#x5728; State &#x4E2D;&#x7684;&#x660E;&#x6587;&#x673A;&#x5BC6;&#x5C31;&#x4F1A;&#x6CC4;&#x9732;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x7684;&#x5B58;&#x50A8;&#x548C;&#x5171;&#x4EAB;&#x95EE;&#x9898;&#xFF0C;Terraform &#x5F15;&#x5165;&#x4E86;&#x8FDC;&#x7A0B;&#x72B6;&#x6001;&#x5B58;&#x50A8;&#x673A;&#x5236;&#xFF0C;&#x4E5F;&#x5C31;&#x662F; Backend&#x3002;Backend &#x662F;&#x4E00;&#x79CD;&#x62BD;&#x8C61;&#x7684;&#x8FDC;&#x7A0B;&#x5B58;&#x50A8;&#x63A5;&#x53E3;&#xFF0C;&#x5982;&#x540C; Provider &#x4E00;&#x6837;&#xFF0C;Backend &#x4E5F;&#x652F;&#x6301;&#x591A;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x8FDC;&#x7A0B;&#x5B58;&#x50A8;&#x670D;&#x52A1;&#xFF1A;</p>
<ul>
<li><code>local</code></li>
<li><code>remote</code></li>
<li><code>azurerm</code></li>
<li><code>consul</code></li>
<li><code>cos</code></li>
<li><code>gcs</code></li>
<li><code>http</code></li>
<li><code>kubernetes</code></li>
<li><code>oss</code></li>
<li><code>pg</code></li>
<li><code>s3</code></li>
</ul>
<p><strong>&#x6CE8;&#x610F;</strong>&#xFF1A;&#x5728; Terraform 1.1.0 &#x4E4B;&#x524D;&#x7684;&#x7248;&#x672C;&#x4E2D;&#xFF0C;Backend &#x5206;&#x4E3A;<em>&#x6807;&#x51C6;</em>&#x548C;<em>&#x589E;&#x5F3A;</em>&#x4E24;&#x79CD;&#x3002;<em>&#x589E;&#x5F3A;</em>&#x662F;&#x4E00;&#x79CD;&#x7279;&#x6B8A;&#x7684; <code>remote</code> Backend&#xFF0C;&#x5B83;&#x65E2;&#x53EF;&#x4EE5;&#x5B58;&#x50A8;&#x72B6;&#x6001;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x6267;&#x884C; Terraform &#x64CD;&#x4F5C;&#x3002;&#x4F46;&#x662F;&#x8FD9;&#x79CD;&#x5206;&#x7C7B;&#x5DF2;&#x88AB;&#x79FB;&#x9664;&#x3002;&#x8BF7;&#x53C2;&#x8003;<a href="https://developer.hashicorp.com/terraform/cli/cloud" target="_blank">&#x4F7F;&#x7528; Terraform Cloud</a> &#x4E86;&#x89E3;&#x5173;&#x4E8E;&#x5B58;&#x50A8;&#x72B6;&#x6001;&#x3001;&#x6267;&#x884C;&#x8FDC;&#x7A0B;&#x64CD;&#x4F5C;&#x4EE5;&#x53CA;&#x76F4;&#x63A5;&#x4ECE; Terraform &#x8C03;&#x7528; Terraform Cloud &#x7684;&#x8BE6;&#x7EC6;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x72B6;&#x6001;&#x9501;&#x662F;&#x6307;&#xFF0C;&#x5F53;&#x9488;&#x5BF9;&#x4E00;&#x4E2A; <code>tfstate</code> &#x8FDB;&#x884C;&#x53D8;&#x66F4;&#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x9488;&#x5BF9;&#x8BE5;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x4E00;&#x628A;&#x5168;&#x5C40;&#x9501;&#xFF0C;&#x786E;&#x4FDD;&#x540C;&#x4E00;&#x65F6;&#x95F4;&#x53EA;&#x80FD;&#x6709;&#x4E00;&#x4E2A;&#x53D8;&#x66F4;&#x88AB;&#x6267;&#x884C;&#x3002;&#x4E0D;&#x540C;&#x7684; Backend &#x5BF9;&#x72B6;&#x6001;&#x9501;&#x7684;&#x652F;&#x6301;&#x4E0D;&#x5C3D;&#x76F8;&#x540C;&#xFF0C;&#x5B9E;&#x73B0;&#x72B6;&#x6001;&#x9501;&#x7684;&#x673A;&#x5236;&#x4E5F;&#x4E0D;&#x5C3D;&#x76F8;&#x540C;&#xFF0C;&#x4F8B;&#x5982; <code>consul</code> Backend&#x5C31;&#x901A;&#x8FC7;&#x4E00;&#x4E2A; <code>.lock</code> &#x8282;&#x70B9;&#x6765;&#x5145;&#x5F53;&#x9501;&#xFF0C;&#x4E00;&#x4E2A; <code>.lockinfo</code> &#x8282;&#x70B9;&#x6765;&#x63CF;&#x8FF0;&#x9501;&#x5BF9;&#x5E94;&#x7684;&#x4F1A;&#x8BDD;&#x4FE1;&#x606F;&#xFF0C;<code>tfstate</code> &#x6587;&#x4EF6;&#x88AB;&#x4FDD;&#x5B58;&#x5728; Backend &#x5B9A;&#x4E49;&#x7684;&#x8DEF;&#x5F84;&#x8282;&#x70B9;&#x5185;&#xFF1B;<code>s3</code> Backend &#x5219;&#x9700;&#x8981;&#x7528;&#x6237;&#x4F20;&#x5165;&#x4E00;&#x4E2A; Dynamodb &#x8868;&#x6765;&#x5B58;&#x653E;&#x9501;&#x4FE1;&#x606F;&#xFF0C;&#x800C; <code>tfstate</code> &#x6587;&#x4EF6;&#x88AB;&#x5B58;&#x50A8;&#x5728; S3 &#x5B58;&#x50A8;&#x6876;&#x91CC;&#xFF0C;&#x7B49;&#x7B49;&#x7B49;&#x7B49;&#x3002;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x6839;&#x636E;&#x5B9E;&#x9645;&#x60C5;&#x51B5;&#xFF0C;&#x6311;&#x9009;&#x81EA;&#x5DF1;&#x5408;&#x9002;&#x7684; Backend&#x3002;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x5C06;&#x4EE5; <code>consul</code> &#x4E3A;&#x8303;&#x4F8B;&#x4E3A;&#x8BFB;&#x8005;&#x6F14;&#x793A; Backend &#x673A;&#x5236;&#x3002;</p>
<h2 id="consul&#x7B80;&#x4ECB;&#x4EE5;&#x53CA;&#x5B89;&#x88C5;"><a name="consul&#x7B80;&#x4ECB;&#x4EE5;&#x53CA;&#x5B89;&#x88C5;" class="anchor-navigation-ex-anchor" href="#consul&#x7B80;&#x4ECB;&#x4EE5;&#x53CA;&#x5B89;&#x88C5;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.4. Consul&#x7B80;&#x4ECB;&#x4EE5;&#x53CA;&#x5B89;&#x88C5;</h2>
<p><a href="https://www.consul.io/" target="_blank">Consul</a> &#x662F; HashiCorp &#x63A8;&#x51FA;&#x7684;&#x4E00;&#x4E2A;&#x5F00;&#x6E90;&#x5DE5;&#x5177;&#xFF0C;&#x4E3B;&#x8981;&#x7528;&#x6765;&#x89E3;&#x51B3;&#x670D;&#x52A1;&#x53D1;&#x73B0;&#x3001;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;&#x4EE5;&#x53CA; Service Mesh &#x7B49;&#x95EE;&#x9898;&#xFF1B;Consul &#x672C;&#x8EAB;&#x4E5F;&#x63D0;&#x4F9B;&#x4E86;&#x7C7B;&#x4F3C; ZooKeeper&#x3001;Etcd &#x8FD9;&#x6837;&#x7684;&#x5206;&#x5E03;&#x5F0F;&#x952E;&#x503C;&#x5B58;&#x50A8;&#x670D;&#x52A1;&#xFF0C;&#x5177;&#x6709;&#x57FA;&#x4E8E; Gossip &#x534F;&#x8BAE;&#x7684;&#x6700;&#x7EC8;&#x4E00;&#x81F4;&#x6027;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x88AB;&#x7528;&#x6765;&#x5145;&#x5F53; Terraform Backend &#x5B58;&#x50A8;&#x3002;</p>
<p>&#x5B89;&#x88C5; Consul &#x5341;&#x5206;&#x7B80;&#x5355;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x662F; Ubuntu &#x7528;&#x6237;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token function">wget</span> -O- https://apt.releases.hashicorp.com/gpg <span class="token operator">|</span> <span class="token function">sudo</span> gpg <span class="token parameter variable">--dearmor</span> <span class="token parameter variable">-o</span> /usr/share/keyrings/hashicorp-archive-keyring.gpg
<span class="token builtin class-name">echo</span> <span class="token string">&quot;deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com <span class="token variable"><span class="token variable">$(</span>lsb_release <span class="token parameter variable">-cs</span><span class="token variable">)</span></span> main&quot;</span> <span class="token operator">|</span> <span class="token function">sudo</span> <span class="token function">tee</span> /etc/apt/sources.list.d/hashicorp.list
<span class="token function">sudo</span> <span class="token function">apt</span> update <span class="token operator">&amp;&amp;</span> <span class="token function">sudo</span> <span class="token function">apt</span> <span class="token function">install</span> consul
</code></pre>
<p>&#x5BF9;&#x4E8E;CentOS&#x7528;&#x6237;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token function">sudo</span> yum <span class="token function">install</span> <span class="token parameter variable">-y</span> yum-utils
<span class="token function">sudo</span> yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
<span class="token function">sudo</span> yum <span class="token parameter variable">-y</span> <span class="token function">install</span> consul
</code></pre>
<p>&#x5BF9;&#x4E8E;Macos&#x7528;&#x6237;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">brew tap hashicorp/tap
brew <span class="token function">install</span> hashicorp/tap/consul
</code></pre>
<p>&#x5BF9;&#x4E8E; Windows &#x7528;&#x6237;&#xFF0C;&#x5982;&#x679C;&#x6309;&#x7167;&#x524D;&#x6587;&#x5B89;&#x88C5; Terraform &#x6559;&#x7A0B;&#x5DF2;&#x7ECF;&#x914D;&#x7F6E;&#x4E86; Chocolatey &#x7684;&#x8BDD;&#xFF1A;</p>
<pre class="language-"><code class="lang-powershell">choco install consul
</code></pre>
<p>&#x5B89;&#x88C5;&#x5B8C;&#x6210;&#x540E;&#x7684;&#x9A8C;&#x8BC1;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ consul
Usage: consul <span class="token punctuation">[</span>--version<span class="token punctuation">]</span> <span class="token punctuation">[</span>--help<span class="token punctuation">]</span> <span class="token operator">&lt;</span>command<span class="token operator">&gt;</span> <span class="token punctuation">[</span><span class="token operator">&lt;</span>args<span class="token operator">&gt;</span><span class="token punctuation">]</span>

Available commands are:
    acl             Interact with Consul<span class="token string">&apos;s ACLs
    agent           Runs a Consul agent
    catalog         Interact with the catalog
    config          Interact with Consul&apos;</span>s Centralized Configurations
    connect         Interact with Consul Connect
    debug           Records a debugging archive <span class="token keyword">for</span> operators
    event           Fire a new event
    <span class="token builtin class-name">exec</span>            Executes a <span class="token builtin class-name">command</span> on Consul nodes
    force-leave     Forces a member of the cluster to enter the <span class="token string">&quot;left&quot;</span> state
    info            Provides debugging information <span class="token keyword">for</span> operators.
    intention       Interact with Connect <span class="token function">service</span> intentions
    <span class="token function">join</span>            Tell Consul agent to <span class="token function">join</span> cluster
    keygen          Generates a new encryption key
    keyring         Manages gossip layer encryption keys
    kv              Interact with the key-value store
    leave           Gracefully leaves the Consul cluster and shuts down
    lock            Execute a <span class="token builtin class-name">command</span> holding a lock
    login           Login to Consul using an auth method
    <span class="token builtin class-name">logout</span>          Destroy a Consul token created with login
    maint           Controls <span class="token function">node</span> or <span class="token function">service</span> maintenance mode
    members         Lists the members of a Consul cluster
    monitor         Stream logs from a Consul agent
    operator        Provides cluster-level tools <span class="token keyword">for</span> Consul operators
    peering         Create and manage peering connections between Consul clusters
    reload          Triggers the agent to reload configuration files
    resource        Interact with Consul&apos;s resources
    rtt             Estimates network round trip <span class="token function">time</span> between nodes
    services        Interact with services
    snapshot        Saves, restores and inspects snapshots of Consul server state
    tls             Builtin helpers <span class="token keyword">for</span> creating CAs and certificates
    troubleshoot    CLI tools <span class="token keyword">for</span> troubleshooting Consul <span class="token function">service</span> mesh
    validate        Validate config files/directories
    version         Prints the Consul version
    <span class="token function">watch</span>           Watch <span class="token keyword">for</span> <span class="token for-or-select variable">changes</span> <span class="token keyword">in</span> Consul
</code></pre>
<p>&#x5B89;&#x88C5;&#x5B8C; Consul &#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x542F;&#x52A8;&#x4E00;&#x4E2A;&#x6D4B;&#x8BD5;&#x7248; Consul &#x670D;&#x52A1;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ consul agent <span class="token parameter variable">-dev</span>
</code></pre>
<p>Consul &#x4F1A;&#x5728;&#x672C;&#x673A; <code>8500</code> &#x7AEF;&#x53E3;&#x5F00;&#x653E; Http &#x7EC8;&#x7ED3;&#x70B9;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6D4F;&#x89C8;&#x5668;&#x8BBF;&#x95EE; <a href="http://localhost:8500" target="_blank">http://localhost:8500</a> &#xFF1A;</p>
<figure id="fig1.3.2.1"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220224455.png" alt="Consul&#x7684;GUI&#x754C;&#x9762;"><figcaption>&#x56FE; 1.3.2/1 - Consul&#x7684;GUI&#x754C;&#x9762;</figcaption></figure>
<h2 id="&#x4F7F;&#x7528;-backend"><a name="&#x4F7F;&#x7528;-backend" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;-backend"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.5. &#x4F7F;&#x7528; Backend</h2>
<p>&#x6211;&#x4EEC;&#x8FD8;&#x662F;&#x5229;&#x7528; LocalStack &#x6765;&#x6267;&#x884C;&#x4E00;&#x6BB5;&#x7B80;&#x5355;&#x7684; Terraform &#x4EE3;&#x7801;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">terraform</span> <span class="token punctuation">{</span>
  <span class="token keyword">required_providers</span> <span class="token punctuation">{</span>
    <span class="token property">aws</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
      <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;hashicorp/aws&quot;</span>
      <span class="token property">version</span> <span class="token punctuation">=</span> <span class="token string">&quot;~&gt;5.0&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">backend<span class="token type variable"> &quot;consul&quot; </span></span><span class="token punctuation">{</span>
    <span class="token property">address</span> <span class="token punctuation">=</span> <span class="token string">&quot;localhost:8500&quot;</span>
    <span class="token property">scheme</span>  <span class="token punctuation">=</span> <span class="token string">&quot;http&quot;</span>
    <span class="token property">path</span>    <span class="token punctuation">=</span> <span class="token string">&quot;localstack-aws&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">provider<span class="token type variable"> &quot;aws&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">access_key</span>                  <span class="token punctuation">=</span> <span class="token string">&quot;test&quot;</span>
  <span class="token property">secret_key</span>                  <span class="token punctuation">=</span> <span class="token string">&quot;test&quot;</span>
  <span class="token property">region</span>                      <span class="token punctuation">=</span> <span class="token string">&quot;us-east-1&quot;</span>
  <span class="token property">s3_use_path_style</span>           <span class="token punctuation">=</span> <span class="token boolean">false</span>
  <span class="token property">skip_credentials_validation</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>
  <span class="token property">skip_metadata_api_check</span>     <span class="token punctuation">=</span> <span class="token boolean">true</span>
  <span class="token property">skip_requesting_account_id</span>  <span class="token punctuation">=</span> <span class="token boolean">true</span>

  <span class="token keyword">endpoints</span> <span class="token punctuation">{</span>
    <span class="token property">apigateway</span>     <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">apigatewayv2</span>   <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">cloudformation</span> <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">cloudwatch</span>     <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">docdb</span>          <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">dynamodb</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ec2</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">es</span>             <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">elasticache</span>    <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">firehose</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">iam</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">kinesis</span>        <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">lambda</span>         <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">rds</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">redshift</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">route53</span>        <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">s3</span>             <span class="token punctuation">=</span> <span class="token string">&quot;http://s3.localhost.localstack.cloud:4566&quot;</span>
    <span class="token property">secretsmanager</span> <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ses</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sns</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sqs</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ssm</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">stepfunctions</span>  <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sts</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">data <span class="token type variable">&quot;aws_ami&quot;</span></span> <span class="token string">&quot;ubuntu&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">most_recent</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>

  <span class="token keyword">filter</span> <span class="token punctuation">{</span>
    <span class="token property">name</span>   <span class="token punctuation">=</span> <span class="token string">&quot;name&quot;</span>
    <span class="token property">values</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727&quot;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">filter</span> <span class="token punctuation">{</span>
    <span class="token property">name</span>   <span class="token punctuation">=</span> <span class="token string">&quot;virtualization-type&quot;</span>
    <span class="token property">values</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;hvm&quot;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>

  <span class="token property">owners</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;099720109477&quot;</span><span class="token punctuation">]</span> <span class="token comment"># Canonical</span>
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;web&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">ami</span>           <span class="token punctuation">=</span> data.aws_ami.ubuntu.id
  <span class="token property">instance_type</span> <span class="token punctuation">=</span> <span class="token string">&quot;t3.micro&quot;</span>

  <span class="token property">tags</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
    <span class="token property">Name</span> <span class="token punctuation">=</span> <span class="token string">&quot;HelloWorld&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728; <code>terraform</code> &#x8282;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x6DFB;&#x52A0;&#x4E86; <code>backend</code> &#x914D;&#x7F6E;&#x8282;&#xFF0C;&#x6307;&#x5B9A;&#x4F7F;&#x7528; <code>localhost:8500</code> &#x4E3A;&#x5730;&#x5740;(&#x4E5F;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x521A;&#x624D;&#x542F;&#x52A8;&#x7684;&#x6D4B;&#x8BD5;&#x7248; Consul &#x670D;&#x52A1;)&#xFF0C;&#x6307;&#x5B9A;&#x4F7F;&#x7528; http &#x534F;&#x8BAE;&#x8BBF;&#x95EE;&#x8BE5;&#x5730;&#x5740;&#xFF0C;&#x6307;&#x5B9A; <code>tfstate</code> &#x6587;&#x4EF6;&#x5B58;&#x653E;&#x5728; Consul &#x952E;&#x503C;&#x5B58;&#x50A8;&#x670D;&#x52A1;&#x7684; <code>localstack-aws</code> &#x8DEF;&#x5F84;&#x4E0B;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x5B8C; <code>terraform apply</code> &#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x8BBF;&#x95EE; <a href="http://localhost:8500/ui/dc1/kv" target="_blank">http://localhost:8500/ui/dc1/kv</a> &#xFF1A;</p>
<figure id="fig1.3.2.2"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230042.png" alt="Consul &#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x540D;&#x4E3A; `localstack-aws` &#x7684;&#x952E;"><figcaption>&#x56FE; 1.3.2/2 - Consul &#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x540D;&#x4E3A; `localstack-aws` &#x7684;&#x952E;</figcaption></figure>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230; <code>localstack-aws</code>&#xFF0C;&#x70B9;&#x51FB;&#x8FDB;&#x5165;&#xFF1A;</p>
<figure id="fig1.3.2.3"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230136.png" alt="&#x952E;&#x7684;&#x5185;&#x5BB9;"><figcaption>&#x56FE; 1.3.2/3 - &#x952E;&#x7684;&#x5185;&#x5BB9;</figcaption></figure>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x539F;&#x672C;&#x4FDD;&#x5B58;&#x5728;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x7684; <code>tfstate</code> &#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x88AB;&#x4FDD;&#x5B58;&#x5728;&#x4E86; Consul &#x7684;&#x540D;&#x4E3A; <code>localstack-aws</code> &#x7684;&#x952E;&#x4E0B;&#x3002;</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x6267;&#x884C; <code>terraform destroy</code> &#x540E;&#xFF0C;&#x91CD;&#x65B0;&#x8BBF;&#x95EE; <a href="http://localhost:8500/ui/dc1/kv" target="_blank">http://localhost:8500/ui/dc1/kv</a> &#xFF1A;</p>
<figure id="fig1.3.2.4"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230312.png" alt="&#x952E;&#x4F9D;&#x7136;&#x5B58;&#x5728;"><figcaption>&#x56FE; 1.3.2/4 - &#x952E;&#x4F9D;&#x7136;&#x5B58;&#x5728;</figcaption></figure>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<code>localstack-aws</code> &#x8FD9;&#x4E2A;&#x952E;&#x4ECD;&#x7136;&#x5B58;&#x5728;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x70B9;&#x51FB;&#x8FDB;&#x53BB;&#xFF1A;</p>
<figure id="fig1.3.2.5"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230350.png" alt="&#x5185;&#x5BB9;&#x5DF2;&#x88AB;&#x6E05;&#x7A7A;"><figcaption>&#x56FE; 1.3.2/5 - &#x5185;&#x5BB9;&#x5DF2;&#x88AB;&#x6E05;&#x7A7A;</figcaption></figure>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x4E3A;&#x7A7A;&#xFF0C;&#x4EE3;&#x8868;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x5DF2;&#x7ECF;&#x88AB;&#x6210;&#x529F;&#x9500;&#x6BC1;&#x3002;</p>
<h2 id="&#x89C2;&#x5BDF;&#x9501;&#x6587;&#x4EF6;"><a name="&#x89C2;&#x5BDF;&#x9501;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x89C2;&#x5BDF;&#x9501;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.6. &#x89C2;&#x5BDF;&#x9501;&#x6587;&#x4EF6;</h2>
<p>&#x90A3;&#x4E48;&#x5728;&#x8FD9;&#x4E2A;&#x8FC7;&#x7A0B;&#x91CC;&#xFF0C;&#x9501;&#x7A76;&#x7ADF;&#x5728;&#x54EA;&#x91CC;&#xFF1F;&#x6211;&#x4EEC;&#x5982;&#x4F55;&#x80FD;&#x591F;&#x4F53;&#x9A8C;&#x5230;&#x9501;&#x7684;&#x5B58;&#x5728;&#xFF1F;&#x8BA9;&#x6211;&#x4EEC;&#x5BF9;&#x4EE3;&#x7801;&#x8FDB;&#x884C;&#x4E00;&#x70B9;&#x4FEE;&#x6539;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">terraform</span> <span class="token punctuation">{</span>
  <span class="token keyword">required_providers</span> <span class="token punctuation">{</span>
    <span class="token property">aws</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
      <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;hashicorp/aws&quot;</span>
      <span class="token property">version</span> <span class="token punctuation">=</span> <span class="token string">&quot;~&gt;5.0&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">backend<span class="token type variable"> &quot;consul&quot; </span></span><span class="token punctuation">{</span>
    <span class="token property">address</span> <span class="token punctuation">=</span> <span class="token string">&quot;localhost:8500&quot;</span>
    <span class="token property">scheme</span>  <span class="token punctuation">=</span> <span class="token string">&quot;http&quot;</span>
    <span class="token property">path</span>    <span class="token punctuation">=</span> <span class="token string">&quot;localstack-aws&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">provider<span class="token type variable"> &quot;aws&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">access_key</span>                  <span class="token punctuation">=</span> <span class="token string">&quot;test&quot;</span>
  <span class="token property">secret_key</span>                  <span class="token punctuation">=</span> <span class="token string">&quot;test&quot;</span>
  <span class="token property">region</span>                      <span class="token punctuation">=</span> <span class="token string">&quot;us-east-1&quot;</span>
  <span class="token property">s3_use_path_style</span>           <span class="token punctuation">=</span> <span class="token boolean">false</span>
  <span class="token property">skip_credentials_validation</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>
  <span class="token property">skip_metadata_api_check</span>     <span class="token punctuation">=</span> <span class="token boolean">true</span>
  <span class="token property">skip_requesting_account_id</span>  <span class="token punctuation">=</span> <span class="token boolean">true</span>

  <span class="token keyword">endpoints</span> <span class="token punctuation">{</span>
    <span class="token property">apigateway</span>     <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">apigatewayv2</span>   <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">cloudformation</span> <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">cloudwatch</span>     <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">docdb</span>          <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">dynamodb</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ec2</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">es</span>             <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">elasticache</span>    <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">firehose</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">iam</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">kinesis</span>        <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">lambda</span>         <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">rds</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">redshift</span>       <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">route53</span>        <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">s3</span>             <span class="token punctuation">=</span> <span class="token string">&quot;http://s3.localhost.localstack.cloud:4566&quot;</span>
    <span class="token property">secretsmanager</span> <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ses</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sns</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sqs</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">ssm</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">stepfunctions</span>  <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
    <span class="token property">sts</span>            <span class="token punctuation">=</span> <span class="token string">&quot;http://localhost:4566&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">data <span class="token type variable">&quot;aws_ami&quot;</span></span> <span class="token string">&quot;ubuntu&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">most_recent</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>

  <span class="token keyword">filter</span> <span class="token punctuation">{</span>
    <span class="token property">name</span>   <span class="token punctuation">=</span> <span class="token string">&quot;name&quot;</span>
    <span class="token property">values</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-20170727&quot;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>

  <span class="token keyword">filter</span> <span class="token punctuation">{</span>
    <span class="token property">name</span>   <span class="token punctuation">=</span> <span class="token string">&quot;virtualization-type&quot;</span>
    <span class="token property">values</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;hvm&quot;</span><span class="token punctuation">]</span>
  <span class="token punctuation">}</span>

  <span class="token property">owners</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;099720109477&quot;</span><span class="token punctuation">]</span> <span class="token comment"># Canonical</span>
<span class="token punctuation">}</span>

<span class="token keyword">resource <span class="token type variable">&quot;aws_instance&quot;</span></span> <span class="token string">&quot;web&quot;</span> <span class="token punctuation">{</span>
  <span class="token property">ami</span>           <span class="token punctuation">=</span> data.aws_ami.ubuntu.id
  <span class="token property">instance_type</span> <span class="token punctuation">=</span> <span class="token string">&quot;t3.micro&quot;</span>

  <span class="token property">tags</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
    <span class="token property">Name</span> <span class="token punctuation">=</span> <span class="token string">&quot;HelloWorld&quot;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">provisioner<span class="token type variable"> &quot;local-exec&quot; </span></span><span class="token punctuation">{</span>
    <span class="token property">command</span> <span class="token punctuation">=</span> <span class="token string">&quot;sleep 1000&quot;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD9;&#x6B21;&#x7684;&#x53D8;&#x5316;&#x662F;&#x6211;&#x4EEC;&#x5728; <code>aws_instance</code> &#x7684;&#x5B9A;&#x4E49;&#x4E0A;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A; <code>local-exec</code> &#x7C7B;&#x578B;&#x7684; Provisioner&#x3002;Provisioner &#x6211;&#x4EEC;&#x5728;&#x540E;&#x7EED;&#x7684;&#x7AE0;&#x8282;&#x4E2D;&#x4F1A;&#x4E13;&#x95E8;&#x53D9;&#x8FF0;&#xFF0C;&#x5728;&#x8FD9;&#x91CC;&#x8BFB;&#x8005;&#x53EA;&#x9700;&#x8981;&#x7406;&#x89E3;&#xFF0C;Terraform &#x8FDB;&#x7A0B;&#x5728;&#x6210;&#x529F;&#x521B;&#x5EFA;&#x4E86;&#x8BE5;&#x8D44;&#x6E90;&#x540E;&#xFF0C;&#x4F1A;&#x5728;&#x6267;&#x884C; Terraform &#x547D;&#x4EE4;&#x884C;&#x7684;&#x673A;&#x5668;&#x4E0A;&#x6267;&#x884C;&#x4E00;&#x6761;&#x547D;&#x4EE4;&#xFF1A;<code>sleep 1000</code>&#xFF0C;&#x8FD9;&#x4E2A;&#x65F6;&#x95F4;&#x8DB3;&#x4EE5;&#x5C06; Terraform &#x8FDB;&#x7A0B;&#x963B;&#x585E;&#x8DB3;&#x591F;&#x957F;&#x7684;&#x65F6;&#x95F4;&#xFF0C;&#x4EE5;&#x4FBF;&#x8BA9;&#x6211;&#x4EEC;&#x89C2;&#x5BDF;&#x9501;&#x4FE1;&#x606F;&#x4E86;&#x3002;&#x5982;&#x679C;&#x8BFB;&#x8005;&#x6B63;&#x5728;&#x4F7F;&#x7528; Windows&#xFF0C;&#x53EF;&#x4EE5;&#x628A; <code>provisioner</code> &#x6539;&#x6210;&#x8FD9;&#x6837;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">provisioner<span class="token type variable"> &quot;local-exec&quot; </span></span><span class="token punctuation">{</span>
  <span class="token property">command</span> <span class="token punctuation">=</span> <span class="token string">&quot;Start-Sleep -s 1000&quot;</span>
  <span class="token property">interpreter</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">&quot;PowerShell&quot;</span>, <span class="token string">&quot;-Command&quot;</span><span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x6267;&#x884C;<code>terraform apply</code>&#xFF0C;&#x8FD9;&#x4E00;&#x6B21; apply &#x5C06;&#x4F1A;&#x88AB; sleep &#x963B;&#x585E;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x6210;&#x529F;&#x5B8C;&#x6210;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">data.aws_ami.ubuntu: Reading<span class="token punctuation">..</span>.
data.aws_ami.ubuntu: Read complete after 1s <span class="token punctuation">[</span>id<span class="token operator">=</span>ami-1e749f67<span class="token punctuation">]</span>

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following  
symbols:
  + create

Terraform will perform the following actions:

  <span class="token comment"># aws_instance.web will be created</span>
  + resource <span class="token string">&quot;aws_instance&quot;</span> <span class="token string">&quot;web&quot;</span> <span class="token punctuation">{</span>
      + ami                                  <span class="token operator">=</span> <span class="token string">&quot;ami-1e749f67&quot;</span>
      + arn                                  <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + associate_public_ip_address          <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + availability_zone                    <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + cpu_core_count                       <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + cpu_threads_per_core                 <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + disable_api_stop                     <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + disable_api_termination              <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + ebs_optimized                        <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + get_password_data                    <span class="token operator">=</span> <span class="token boolean">false</span>
      + host_id                              <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + host_resource_group_arn              <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + iam_instance_profile                 <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + <span class="token function">id</span>                                   <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + instance_initiated_shutdown_behavior <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + instance_lifecycle                   <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + instance_state                       <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + instance_type                        <span class="token operator">=</span> <span class="token string">&quot;t3.micro&quot;</span>
      + ipv6_address_count                   <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + ipv6_addresses                       <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + key_name                             <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + monitoring                           <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + outpost_arn                          <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + password_data                        <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + placement_group                      <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + placement_partition_number           <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + primary_network_interface_id         <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + private_dns                          <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + private_ip                           <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + public_dns                           <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + public_ip                            <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + secondary_private_ips                <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + security_groups                      <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + source_dest_check                    <span class="token operator">=</span> <span class="token boolean">true</span>
      + spot_instance_request_id             <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + subnet_id                            <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + tags                                 <span class="token operator">=</span> <span class="token punctuation">{</span>
          + <span class="token string">&quot;Name&quot;</span> <span class="token operator">=</span> <span class="token string">&quot;HelloWorld&quot;</span>
        <span class="token punctuation">}</span>
      + tags_all                             <span class="token operator">=</span> <span class="token punctuation">{</span>
          + <span class="token string">&quot;Name&quot;</span> <span class="token operator">=</span> <span class="token string">&quot;HelloWorld&quot;</span>
        <span class="token punctuation">}</span>
      + tenancy                              <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + user_data                            <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + user_data_base64                     <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
      + user_data_replace_on_change          <span class="token operator">=</span> <span class="token boolean">false</span>
      + vpc_security_group_ids               <span class="token operator">=</span> <span class="token punctuation">(</span>known after apply<span class="token punctuation">)</span>
    <span class="token punctuation">}</span>

Plan: <span class="token number">1</span> to add, <span class="token number">0</span> to change, <span class="token number">0</span> to destroy.
aws_instance.web: Creating<span class="token punctuation">..</span>.
aws_instance.web: Still creating<span class="token punctuation">..</span>. <span class="token punctuation">[</span>10s elapsed<span class="token punctuation">]</span>
aws_instance.web: Provisioning with <span class="token string">&apos;local-exec&apos;</span><span class="token punctuation">..</span>.
aws_instance.web <span class="token punctuation">(</span>local-exec<span class="token punctuation">)</span>: Executing: <span class="token punctuation">[</span><span class="token string">&quot;PowerShell&quot;</span> <span class="token string">&quot;-Command&quot;</span> <span class="token string">&quot;Start-Sleep -s 1000&quot;</span><span class="token punctuation">]</span>
aws_instance.web: Still creating<span class="token punctuation">..</span>. <span class="token punctuation">[</span>20s elapsed<span class="token punctuation">]</span>
<span class="token punctuation">..</span>.
</code></pre>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x91CD;&#x65B0;&#x8BBF;&#x95EE; <a href="http://localhost:8500/ui/dc1/kv" target="_blank">http://localhost:8500/ui/dc1/kv</a> &#xFF1A;</p>
<figure id="fig1.3.2.6"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225100309.png" alt="&#x591A;&#x4E86;&#x4E00;&#x4E2A;&#x540C;&#x540D;&#x7684;&#x6587;&#x4EF6;&#x5939;"><figcaption>&#x56FE; 1.3.2/6 - &#x591A;&#x4E86;&#x4E00;&#x4E2A;&#x540C;&#x540D;&#x7684;&#x6587;&#x4EF6;&#x5939;</figcaption></figure>
<p>&#x8FD9;&#x4E00;&#x6B21;&#x60C5;&#x51B5;&#x53D1;&#x751F;&#x4E86;&#x53D8;&#x5316;&#xFF0C;&#x6211;&#x4EEC;&#x770B;&#x5230;&#x9664;&#x4E86;<code>localstack-aws</code>&#x8FD9;&#x4E2A;&#x952E;&#x4E4B;&#x5916;&#xFF0C;&#x8FD8;&#x591A;&#x4E86;&#x4E00;&#x4E2A;&#x540C;&#x540D;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x70B9;&#x51FB;&#x8FDB;&#x5165;&#x6587;&#x4EF6;&#x5939;&#xFF1A;</p>
<figure id="fig1.3.2.7"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225100354.png" alt="localstack-aws &#x6587;&#x4EF6;&#x5939;&#x5185;&#x90E8;"><figcaption>&#x56FE; 1.3.2/7 - localstack-aws &#x6587;&#x4EF6;&#x5939;&#x5185;&#x90E8;</figcaption></figure>
<p>&#x5728;&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x6210;&#x529F;&#x89C2;&#x6D4B;&#x5230;&#x4E86; <code>.lock</code> &#x548C; <code>.lockinfo</code> &#x6587;&#x4EF6;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x70B9;&#x51FB; <code>.lock</code> &#x770B;&#x770B;&#xFF1A;</p>
<figure id="fig1.3.2.8"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180803.png" alt="`.lock` &#x5185;&#x5BB9;"><figcaption>&#x56FE; 1.3.2/8 - `.lock` &#x5185;&#x5BB9;</figcaption></figure>
<p>Consul UI&#x63D0;&#x9192;&#x6211;&#x4EEC;&#xFF0C;&#x8BE5;&#x952E;&#x503C;&#x5BF9;&#x76EE;&#x524D;&#x6B63;&#x88AB;&#x9501;&#x5B9A;&#xFF0C;&#x800C;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x662F;&#x7A7A;&#x7684;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x67E5;&#x770B; <code>.lockinfo</code> &#x7684;&#x5185;&#x5BB9;&#xFF1A;</p>
<figure id="fig1.3.2.9"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180852.png" alt="`.lockinfo` &#x5185;&#x5BB9;"><figcaption>&#x56FE; 1.3.2/9 - `.lockinfo` &#x5185;&#x5BB9;</figcaption></figure>
<p><a name="lockid"></a><code>.lockinfo</code> &#x91CC;&#x8BB0;&#x5F55;&#x4E86;&#x9501; <code>ID</code>&#x3001;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x4EE5;&#x53CA;&#x5176;&#x4ED6;&#x7684;&#x4E00;&#x4E9B;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x53E6;&#x8D77;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x547D;&#x4EE4;&#x884C;&#x7A97;&#x53E3;&#xFF0C;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x5C1D;&#x8BD5;&#x53E6;&#x4E00;&#x6B21;&#x6267;&#x884C; <code>terraform apply</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform apply
Acquiring state lock. This may take a few moments<span class="token punctuation">..</span>.
&#x2577;
&#x2502; Error: Error acquiring the state lock
&#x2502; 
&#x2502; Error message: Lock Info:
&#x2502;   ID:        11c859fd-d3e5-4eab-46d6-586b73133430
&#x2502;   Path:      localstack-aws
&#x2502;   Operation: OperationTypeApply
&#x2502;   Who:       ***
&#x2502;   Version:   <span class="token number">1.7</span>.3
&#x2502;   Created:   <span class="token number">2024</span>-02-25 02:00:21.3700184 +0000 UTC
&#x2502;   Info:      consul session: 11c859fd-d3e5-4eab-46d6-586b73133430
&#x2502;
&#x2502;
&#x2502; Terraform acquires a state lock to protect the state from being written
&#x2502; by multiple <span class="token function">users</span> at the same time. Please resolve the issue above and try
&#x2502; again. For <span class="token function">most</span> commands, you can disable locking with the <span class="token string">&quot;-lock=false&quot;</span>
&#x2502; flag, but this is not recommended.
&#x2575;
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x540C;&#x65F6;&#x53E6;&#x4E00;&#x4E2A;&#x4EBA;&#x8BD5;&#x56FE;&#x5BF9;&#x540C;&#x4E00;&#x4E2A; <code>tfstate</code> &#x6267;&#x884C;&#x53D8;&#x66F4;&#x7684;&#x5C1D;&#x8BD5;&#x5931;&#x8D25;&#x4E86;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x65E0;&#x6CD5;&#x987A;&#x5229;&#x83B7;&#x53D6;&#x5230;&#x9501;&#x3002;</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x7528; <code>ctrl-c</code> &#x7EC8;&#x6B62;&#x539F;&#x5148;&#x88AB;&#x963B;&#x585E;&#x7684; <code>terraform apply</code> &#x7684;&#x6267;&#x884C;&#xFF0C;&#x7136;&#x540E;&#x7528; <code>terraform force-unlock 11c859fd-d3e5-4eab-46d6-586b73133430</code> &#x89E3;&#x9501;&#xFF1A;</p>
<pre class="language-"><code class="lang-Bash">$ terraform force-unlock 11c859fd-d3e5-4eab-46d6-586b73133430
Do you really want to force-unlock?
  Terraform will remove the lock on the remote state.
  This will allow local Terraform commands to modify this state, even though it
  may still be in use. Only &apos;yes&apos; will be accepted to confirm.

  Enter a value: yes

Terraform state has been successfully unlocked!

The state has been unlocked, and Terraform commands should now be able to
obtain a new lock on the remote state.
</code></pre>
<p>&#x7136;&#x540E;&#x91CD;&#x65B0;&#x8BBF;&#x95EE; <a href="http://localhost:8500/ui/dc1/kv" target="_blank">http://localhost:8500/ui/dc1/kv</a> &#xFF1A;</p>
<figure id="fig1.3.2.10"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225101100.png" alt="&#x91CD;&#x65B0;&#x8BBF;&#x95EE;Consul"><figcaption>&#x56FE; 1.3.2/10 - &#x91CD;&#x65B0;&#x8BBF;&#x95EE;Consul</figcaption></figure>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x5305;&#x542B;&#x9501;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x6D88;&#x5931;&#x4E86;&#x3002;</p>
<h2 id="backend-&#x914D;&#x7F6E;&#x7684;&#x52A8;&#x6001;&#x8D4B;&#x503C;"><a name="backend-&#x914D;&#x7F6E;&#x7684;&#x52A8;&#x6001;&#x8D4B;&#x503C;" class="anchor-navigation-ex-anchor" href="#backend-&#x914D;&#x7F6E;&#x7684;&#x52A8;&#x6001;&#x8D4B;&#x503C;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.7. Backend &#x914D;&#x7F6E;&#x7684;&#x52A8;&#x6001;&#x8D4B;&#x503C;</h2>
<p>&#x6709;&#x4E9B;&#x8BFB;&#x8005;&#x4F1A;&#x6CE8;&#x610F;&#x5230;&#xFF0C;&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#x6211;&#x6240;&#x5199;&#x7684;&#x4EE3;&#x7801;&#x91CC;&#x7684;&#x914D;&#x7F6E;&#x9879;&#x57FA;&#x672C;&#x90FD;&#x662F;&#x786C;&#x7F16;&#x7801;&#x7684;&#xFF0C;Terraform &#x662F;&#x5426;&#x652F;&#x6301;&#x8FD0;&#x884C;&#x65F6;&#x7528;&#x53D8;&#x91CF;&#x52A8;&#x6001;&#x8D4B;&#x503C;&#xFF1F;&#x7B54;&#x6848;&#x662F;&#x652F;&#x6301;&#x7684;&#xFF0C;Terraform &#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>variable</code> &#x53D8;&#x91CF;&#x6765;&#x4F20;&#x503C;&#x7ED9; <code>provider</code>&#x3001;<code>data</code> &#x548C; <code>resource</code>&#x3002;</p>
<p>&#x4F46;&#x6709;&#x4E00;&#x4E9B;&#x4F8B;&#x5916;&#xFF0C;&#x5176;&#x4E2D;&#x5C31;&#x6709; <code>backend</code> &#x914D;&#x7F6E;&#x3002;<code>backend</code> &#x914D;&#x7F6E;&#x53EA;&#x5141;&#x8BB8;&#x786C;&#x7F16;&#x7801;&#xFF0C;&#x6216;&#x8005;&#x4E0D;&#x4F20;&#x503C;&#x3002;</p>
<p>&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x662F;&#x56E0;&#x4E3A; Terraform &#x8FD0;&#x884C;&#x65F6;&#x672C;&#x8EAB;&#x8BBE;&#x8BA1;&#x7684;&#x8FD0;&#x884C;&#x987A;&#x5E8F;&#x5BFC;&#x81F4;&#x7684;&#xFF0C;&#x4E00;&#x76F4;&#x5230; 2019 &#x5E74; 05 &#x6708;&#x5B98;&#x65B9;&#x624D;&#x7ED9;&#x51FA;&#x4E86;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF0C;&#x90A3;&#x5C31;&#x662F;&#x201C;&#x90E8;&#x5206;&#x914D;&#x7F6E;&#x201C;(partial configuration)&#x3002;</p>
<p>&#x7B80;&#x5355;&#x6765;&#x8BF4;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728; Terraform &#x4EE3;&#x7801;&#x7684; <code>backend</code> &#x58F0;&#x660E;&#x4E2D;&#x4E0D;&#x7ED9;&#x51FA;&#x5177;&#x4F53;&#x7684;&#x914D;&#x7F6E;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token keyword">terraform</span> <span class="token punctuation">{</span>
  <span class="token keyword">required_providers</span> <span class="token punctuation">{</span>
    <span class="token property">aws</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span>
      <span class="token property">source</span> <span class="token punctuation">=</span> <span class="token string">&quot;hashicorp/aws&quot;</span>
      <span class="token property">version</span> <span class="token punctuation">=</span> <span class="token string">&quot;~&gt;5.0&quot;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">backend<span class="token type variable"> &quot;consul&quot; </span></span><span class="token punctuation">{</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x800C;&#x5728;&#x53E6;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x7ED9;&#x51FA;&#x76F8;&#x5173;&#x914D;&#x7F6E;&#xFF0C;&#x4F8B;&#x5982;&#x6211;&#x4EEC;&#x5728;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <code>backend.hcl</code> &#x7684;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre class="language-"><code class="lang-hcl"><span class="token property">address</span> <span class="token punctuation">=</span> <span class="token string">&quot;localhost:8500&quot;</span>
<span class="token property">scheme</span>  <span class="token punctuation">=</span> <span class="token string">&quot;http&quot;</span>
<span class="token property">path</span>    <span class="token punctuation">=</span> <span class="token string">&quot;localstack-aws&quot;</span>
</code></pre>
<p>&#x672C;&#x8D28;&#x4E0A;&#x6211;&#x4EEC;&#x5C31;&#x662F;&#x628A;&#x539F;&#x672C;&#x5C5E;&#x4E8E; <code>backend consul</code> &#x5757;&#x7684;&#x5C5E;&#x6027;&#x8D4B;&#x503C;&#x4EE3;&#x7801;&#x642C;&#x8FC1;&#x5230;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x7684; hcl &#x6587;&#x4EF6;&#x5185;&#xFF0C;&#x7136;&#x540E;&#x6211;&#x4EEC;&#x6267;&#x884C; <code>terraform init</code> &#x65F6;&#x9644;&#x52A0; <code>backend-config</code> &#x53C2;&#x6570;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform init -backend-config<span class="token operator">=</span>backend.hcl
</code></pre>
<p>&#x8FD9;&#x6837;&#x4E5F;&#x53EF;&#x4EE5;&#x521D;&#x59CB;&#x5316;&#x6210;&#x529F;&#x3002;&#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x6253;&#x8865;&#x4E01;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x590D;&#x7528;&#x4ED6;&#x4EBA;&#x9884;&#x5148;&#x5199;&#x597D;&#x7684; Terraform &#x4EE3;&#x7801;&#xFF0C;&#x5728;&#x6267;&#x884C;&#x65F6;&#x628A;&#x5C5E;&#x4E8E;&#x6211;&#x4EEC;&#x81EA;&#x5DF1;&#x7684; Backend &#x914D;&#x7F6E;&#x4FE1;&#x606F;&#x4EE5;&#x72EC;&#x7ACB;&#x7684; <code>backend-config</code> &#x6587;&#x4EF6;&#x7684;&#x5F62;&#x5F0F;&#x4F20;&#x5165;&#x6765;&#x8FDB;&#x884C;&#x521D;&#x59CB;&#x5316;&#x3002;</p>
<h2 id="backend-&#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;"><a name="backend-&#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;" class="anchor-navigation-ex-anchor" href="#backend-&#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.8. Backend &#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;</h2>
<p>Backend &#x672C;&#x8EAB;&#x5E76;&#x6CA1;&#x6709;&#x8BBE;&#x8BA1;&#x4EFB;&#x4F55;&#x7684;&#x6743;&#x9650;&#x4EE5;&#x53CA;&#x7248;&#x672C;&#x63A7;&#x5236;&#xFF0C;&#x8FD9;&#x65B9;&#x9762;&#x5B8C;&#x5168;&#x4F9D;&#x8D56;&#x4E8E;&#x5177;&#x4F53;&#x7684; Backend &#x5B9E;&#x73B0;&#x3002;&#x4EE5; AWS S3 &#x4E3A;&#x4F8B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x9488;&#x5BF9;&#x4E0D;&#x540C;&#x7684; Bucket &#x8BBE;&#x7F6E;&#x4E0D;&#x540C;&#x7684; IAM&#xFF0C;&#x7528;&#x4EE5;&#x9632;&#x6B62;&#x5F00;&#x53D1;&#x6D4B;&#x8BD5;&#x4EBA;&#x5458;&#x76F4;&#x63A5;&#x64CD;&#x4F5C;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#xFF0C;&#x6216;&#x662F;&#x7ED9;&#x4E88;&#x90E8;&#x5206;&#x4EBA;&#x5458;&#x5BF9;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x7684;&#x53EA;&#x8BFB;&#x6743;&#x9650;&#xFF1B;&#x53E6;&#x5916;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x5F00;&#x542F; S3 &#x7684;&#x7248;&#x672C;&#x63A7;&#x5236;&#x529F;&#x80FD;&#xFF0C;&#x4EE5;&#x9632;&#x6211;&#x4EEC;&#x9519;&#x8BEF;&#x4FEE;&#x6539;&#x4E86;&#x72B6;&#x6001;&#x6587;&#x4EF6;(Terraform &#x547D;&#x4EE4;&#x884C;&#x6709;&#x4FEE;&#x6539;&#x72B6;&#x6001;&#x7684;&#x76F8;&#x5173;&#x6307;&#x4EE4;)&#x3002;</p>
<h2 id="&#x72B6;&#x6001;&#x7684;&#x9694;&#x79BB;&#x5B58;&#x50A8;"><a name="&#x72B6;&#x6001;&#x7684;&#x9694;&#x79BB;&#x5B58;&#x50A8;" class="anchor-navigation-ex-anchor" href="#&#x72B6;&#x6001;&#x7684;&#x9694;&#x79BB;&#x5B58;&#x50A8;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.9. &#x72B6;&#x6001;&#x7684;&#x9694;&#x79BB;&#x5B58;&#x50A8;</h2>
<p>&#x6211;&#x4EEC;&#x8BB2;&#x5B8C; Backend&#xFF0C;&#x73B0;&#x5728;&#x8981;&#x8BA8;&#x8BBA;&#x53E6;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#x3002;&#x5047;&#x8BBE;&#x6211;&#x4EEC;&#x7684; Terraform &#x4EE3;&#x7801;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x901A;&#x7528;&#x7684;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#xFF0C;&#x6BD4;&#x5982;&#x8BF4;&#x662F;&#x4E91;&#x7AEF;&#x7684;&#x4E00;&#x4E2A; EKS&#x3001;AKS &#x96C6;&#x7FA4;&#xFF0C;&#x6216;&#x8005;&#x662F;&#x4E00;&#x4E2A;&#x57FA;&#x4E8E; S3 &#x7684;&#x9759;&#x6001;&#x7F51;&#x7AD9;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x53EF;&#x80FD;&#x8981;&#x4E3A;&#x5F88;&#x591A;&#x56E2;&#x961F;&#x521B;&#x5EFA;&#x5E76;&#x7EF4;&#x62A4;&#x8FD9;&#x4E9B;&#x76F8;&#x4F3C;&#x4F46;&#x8981;&#x5F7C;&#x6B64;&#x9694;&#x79BB;&#x7684; Stack&#xFF0C;&#x53C8;&#x6216;&#x8005;&#x6211;&#x4EEC;&#x8981;&#x4E3A;&#x90E8;&#x7F72;&#x7684;&#x5E94;&#x7528;&#x7EF4;&#x62A4;&#x5F00;&#x53D1;&#x3001;&#x6D4B;&#x8BD5;&#x3001;&#x9884;&#x53D1;&#x5E03;&#x3001;&#x751F;&#x4EA7;&#x56DB;&#x5957;&#x4E0D;&#x540C;&#x7684;&#x90E8;&#x7F72;&#x3002;&#x90A3;&#x4E48;&#x8BE5;&#x5982;&#x4F55;&#x505A;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x90E8;&#x7F72;&#xFF0C;&#x5F7C;&#x6B64;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x9694;&#x79BB;&#x5B58;&#x50A8;&#x548C;&#x7BA1;&#x7406;&#x5462;&#xFF1F;</p>
<p>&#x4E00;&#x79CD;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x5206;&#x6210;&#x4E0D;&#x540C;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x5B58;&#x50A8;&#x3002;</p>
<figure id="fig1.3.2.11"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-17/1605571444613-image.png" alt="&#x5C06;&#x4EE3;&#x7801;&#x590D;&#x5236;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x4FDD;&#x5B58;"><figcaption>&#x56FE; 1.3.2/11 - &#x5C06;&#x4EE3;&#x7801;&#x590D;&#x5236;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x4FDD;&#x5B58;</figcaption></figure>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x628A;&#x4E0D;&#x540C;&#x4EA7;&#x54C1;&#x4E0D;&#x540C;&#x90E8;&#x95E8;&#x4F7F;&#x7528;&#x7684;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x5206;&#x6210;&#x4E0D;&#x540C;&#x7684;&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x5728;&#x6587;&#x4EF6;&#x5939;&#x5185;&#x7EF4;&#x62A4;&#x76F8;&#x540C;&#x7684;&#x4EE3;&#x7801;&#x6587;&#x4EF6;&#xFF0C;&#x914D;&#x7F6E;&#x4E0D;&#x540C;&#x7684; <code>backend-config</code>&#xFF0C;&#x628A;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x4FDD;&#x5B58;&#x5230;&#x4E0D;&#x540C;&#x7684; Backend &#x4E0A;&#x3002;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x7ED9;&#x4E88;&#x6700;&#x5927;&#x7A0B;&#x5EA6;&#x7684;&#x9694;&#x79BB;&#xFF0C;&#x7F3A;&#x70B9;&#x662F;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x62F7;&#x8D1D;&#x8BB8;&#x591A;&#x4EFD;&#x76F8;&#x540C;&#x7684;&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x7B2C;&#x4E8C;&#x79CD;&#x66F4;&#x52A0;&#x8F7B;&#x91CF;&#x7EA7;&#x7684;&#x65B9;&#x6CD5;&#x5C31;&#x662F; Workspace&#x3002;&#x6CE8;&#x610F;&#xFF0C;Terraform &#x5F00;&#x6E90;&#x7248;&#x7684; Workspace &#x4E0E; Terraform Cloud &#x4E91;&#x670D;&#x52A1;&#x7684; Workspace &#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x4E24;&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x6982;&#x5FF5;&#xFF0C;&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x4ECB;&#x7ECD;&#x7684;&#x662F;&#x5F00;&#x6E90;&#x7248;&#x7684; Workspace&#x3002;</p>
<p>Workspace &#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x5728;&#x540C;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x5939;&#x5185;&#xFF0C;&#x4F7F;&#x7528;&#x540C;&#x6837;&#x7684; Backend &#x914D;&#x7F6E;&#xFF0C;&#x4F46;&#x53EF;&#x4EE5;&#x7EF4;&#x62A4;&#x4EFB;&#x610F;&#x591A;&#x4E2A;&#x5F7C;&#x6B64;&#x9694;&#x79BB;&#x7684;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x3002;&#x8FD8;&#x662F;&#x6211;&#x4EEC;&#x521A;&#x624D;&#x90A3;&#x4E2A;&#x4F7F;&#x7528;&#x6D4B;&#x8BD5; Consul &#x670D;&#x52A1;&#x4F5C;&#x4E3A; Backend &#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<figure id="fig1.3.2.12"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225174932.png" alt="&#x91CD;&#x65B0;&#x8BBF;&#x95EE; Consul&#xFF0C;&#x76EE;&#x524D;&#x6709;&#x4E00;&#x4E2A;&#x952E;"><figcaption>&#x56FE; 1.3.2/12 - &#x91CD;&#x65B0;&#x8BBF;&#x95EE; Consul&#xFF0C;&#x76EE;&#x524D;&#x6709;&#x4E00;&#x4E2A;&#x952E;</figcaption></figure>
<p>&#x5F53;&#x524D;&#x6211;&#x4EEC;&#x6709;&#x4E00;&#x4E2A;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#xFF0C;&#x540D;&#x5B57;&#x662F; <code>localstack-aws</code>&#x3002;&#x7136;&#x540E;&#x6211;&#x4EEC;&#x5728;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x4E0B;&#x6267;&#x884C;&#x8FD9;&#x6837;&#x7684;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform workspace new feature1
Created and switched to workspace <span class="token string">&quot;feature1&quot;</span><span class="token operator">!</span>

You&apos;re now on a new, empty workspace. Workspaces isolate their state,
so <span class="token keyword">if</span> you run <span class="token string">&quot;terraform plan&quot;</span> Terraform will not see any existing state
<span class="token keyword">for</span> this configuration.
</code></pre>
<p>&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>workspace</code> &#x547D;&#x4EE4;&#xFF0C;&#x6211;&#x4EEC;&#x6210;&#x529F;&#x521B;&#x5EFA;&#x4E86;&#x540D;&#x4E3A; <code>feature1</code> &#x7684; Workspace&#x3002;&#x8FD9;&#x65F6;&#x6211;&#x4EEC;&#x89C2;&#x5BDF; <code>.terraform</code> &#x6587;&#x4EF6;&#x5939;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token punctuation">..</span>
&#x251C;&#x2500;&#x2500; environment
&#x251C;&#x2500;&#x2500; providers
&#x2502;        &#x2514;&#x2500;&#x2500; registry.terraform.io
&#x2502;             &#x2514;&#x2500;&#x2500; hashicorp
&#x2502;                 &#x2514;&#x2500;&#x2500; aws
&#x2502;                     &#x2514;&#x2500;&#x2500; <span class="token number">5.38</span>.0
<span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x4F1A;&#x53D1;&#x73B0;&#x591A;&#x4E86;&#x4E00;&#x4E2A; <code>environment</code> &#x6587;&#x4EF6;&#xFF0C;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x662F; <code>feature1</code>&#x3002;&#x8FD9;&#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F; Terraform &#x7528;&#x6765;&#x4FDD;&#x5B58;&#x5F53;&#x524D;&#x4E0A;&#x4E0B;&#x6587;&#x73AF;&#x5883;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x54EA;&#x4E2A; Workspace &#x7684;&#x6587;&#x4EF6;&#x3002;</p>
<figure id="fig1.3.2.13"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225175538.png" alt="Consul &#x4E2D;&#x591A;&#x4E86;&#x4E00;&#x4E2A; `localstack-aws-env:feature1`"><figcaption>&#x56FE; 1.3.2/13 - Consul &#x4E2D;&#x591A;&#x4E86;&#x4E00;&#x4E2A; `localstack-aws-env:feature1`</figcaption></figure>
<p>&#x91CD;&#x65B0;&#x89C2;&#x5BDF; Consul &#x5B58;&#x50A8;&#x4F1A;&#x53D1;&#x73B0;&#x591A;&#x4E86;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;<code>localstack-aws-env:feature1</code>&#x3002;&#x8FD9;&#x5C31;&#x662F; Terraform &#x4E3A; <code>feature1</code> &#x8FD9;&#x4E2A; Workspace &#x521B;&#x5EFA;&#x7684;&#x72EC;&#x7ACB;&#x7684;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x6267;&#x884C;&#x4E00;&#x4E0B; apply&#xFF0C;&#x7136;&#x540E;&#x518D;&#x770B;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;&#xFF1A;</p>
<figure id="fig1.3.2.14"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225175806.png" alt="&#x6B64;&#x65F6; `localstack-aws-env:feature1` &#x7684;&#x5185;&#x5BB9;"><figcaption>&#x56FE; 1.3.2/14 - &#x6B64;&#x65F6; `localstack-aws-env:feature1` &#x7684;&#x5185;&#x5BB9;</figcaption></figure>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;&#x72B6;&#x6001;&#x88AB;&#x6210;&#x529F;&#x5199;&#x5165;&#x4E86; <code>feature1</code> &#x7684;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x6765;&#x67E5;&#x8BE2;&#x5F53;&#x524D; Backend &#x4E0B;&#x6240;&#x6709;&#x7684; Workspace&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform workspace list
  default
* feature1
</code></pre>
<p>&#x6211;&#x4EEC;&#x6709; <code>default</code> &#x548C; <code>feature1</code> &#x4E24;&#x4E2A; Workspace&#xFF0C;&#x5F53;&#x524D;&#x6211;&#x4EEC;&#x5DE5;&#x4F5C;&#x5728; <code>feature1</code> &#x4E0A;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x5207;&#x6362;&#x56DE; <code>default</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform workspace <span class="token keyword">select</span> default
Switched to workspace <span class="token string">&quot;default&quot;</span><span class="token builtin class-name">.</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x786E;&#x8BA4;&#x6211;&#x4EEC;&#x6210;&#x529F;&#x5207;&#x6362;&#x56DE;&#x4E86; <code>default</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform workspace show
default
</code></pre>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x5220;&#x9664; <code>feature1</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform workspace delete feature1
&#x2577;
&#x2502; Error: Workspace is not empty
&#x2502;
&#x2502; Workspace <span class="token string">&quot;feature1&quot;</span> is currently tracking the following resource instances:
&#x2502;   - aws_instance.web
&#x2502;
&#x2502; Deleting this workspace would cause Terraform to lose track of any associated remote objects, <span class="token function">which</span> would <span class="token keyword">then</span> require you to    
&#x2502; delete them manually outside of Terraform. You should destroy these objects with Terraform before deleting the workspace.        
&#x2502;
&#x2502; If you want to delete this workspace anyway, and have Terraform forget about these managed objects, use the <span class="token parameter variable">-force</span> option to     
&#x2502; disable this safety check.
&#x2575;
</code></pre>
<p>Terraform &#x53D1;&#x73B0; <code>feature1</code> &#x8FD8;&#x6709;&#x8D44;&#x6E90;&#x6CA1;&#x6709;&#x88AB;&#x9500;&#x6BC1;&#xFF0C;&#x6240;&#x4EE5;&#x5B83;&#x62D2;&#x7EDD;&#x4E86;&#x6211;&#x4EEC;&#x7684;&#x5220;&#x9664;&#x8BF7;&#x6C42;&#x3002;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x76EE;&#x524D;&#x662F;&#x4F7F;&#x7528; LocalStack &#x6A21;&#x62DF;&#x7684;&#x4F8B;&#x5B50;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x4F1A;&#x6709;&#x8D44;&#x6E90;&#x6CC4;&#x6F0F;&#x7684;&#x95EE;&#x9898;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x5F3A;&#x5236;&#x5220;&#x9664; <code>feature1</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">$ terraform workspace delete <span class="token parameter variable">-force</span> feature1
Deleted workspace <span class="token string">&quot;feature1&quot;</span><span class="token operator">!</span>
WARNING: <span class="token string">&quot;feature1&quot;</span> was non-empty.
The resources managed by the deleted workspace may still exist,
but are no longer manageable by Terraform since the state has
been deleted.
</code></pre>
<p>&#x518D;&#x89C2;&#x5BDF; Consul &#x5B58;&#x50A8;&#xFF0C;&#x5C31;&#x4F1A;&#x53D1;&#x73B0; <code>feature1</code> &#x7684;&#x72B6;&#x6001;&#x6587;&#x4EF6;&#x88AB;&#x5220;&#x9664;&#x4E86;&#xFF1A;</p>
<figure id="fig1.3.2.15"><img src="https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180126.png" alt="`localstack-aws-env:feature1` &#x88AB;&#x5220;&#x9664;&#x4E86;"><figcaption>&#x56FE; 1.3.2/15 - `localstack-aws-env:feature1` &#x88AB;&#x5220;&#x9664;&#x4E86;</figcaption></figure>
<p>&#x76EE;&#x524D;&#x652F;&#x6301;&#x591A;&#x5DE5;&#x4F5C;&#x533A;&#x7684; Backend &#x6709;&#xFF1A;</p>
<ul>
<li>AzureRM</li>
<li>Consulf</li>
<li>COS</li>
<li>GCS</li>
<li>Kubernetes</li>
<li>Local</li>
<li>OSS</li>
<li>Postgres</li>
<li>Remote</li>
<li>S3</li>
</ul>
<h2 id="&#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x79CD;&#x9694;&#x79BB;"><a name="&#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x79CD;&#x9694;&#x79BB;" class="anchor-navigation-ex-anchor" href="#&#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x79CD;&#x9694;&#x79BB;"><i class="fa fa-link" aria-hidden="true"></i></a>1.3.2.1.10. &#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x79CD;&#x9694;&#x79BB;</h2>
<p>&#x76F8;&#x6BD4;&#x8D77;&#x591A;&#x6587;&#x4EF6;&#x5939;&#x9694;&#x79BB;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x8BF4;&#xFF0C;&#x57FA;&#x4E8E; Workspace &#x7684;&#x9694;&#x79BB;&#x66F4;&#x52A0;&#x7B80;&#x5355;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x4FDD;&#x5B58;&#x4E00;&#x4EFD;&#x4EE3;&#x7801;&#xFF0C;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x4E0D;&#x9700;&#x8981;&#x4E3A; Workspace &#x7F16;&#x5199;&#x989D;&#x5916;&#x4EE3;&#x7801;&#xFF0C;&#x7528;&#x547D;&#x4EE4;&#x884C;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x4E0D;&#x540C;&#x5DE5;&#x4F5C;&#x533A;&#x4E4B;&#x95F4;&#x6765;&#x56DE;&#x5207;&#x6362;&#x3002;</p>
<p>&#x4F46;&#x662F; Workspace &#x7684;&#x7F3A;&#x70B9;&#x4E5F;&#x540C;&#x6837;&#x660E;&#x663E;&#xFF0C;&#x7531;&#x4E8E;&#x6240;&#x6709;&#x5DE5;&#x4F5C;&#x533A;&#x7684; Backend &#x914D;&#x7F6E;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x6709;&#x6743;&#x8BFB;&#x5199;&#x67D0;&#x4E00;&#x4E2A; Workspace &#x7684;&#x4EBA;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x540C;&#x4E00;&#x4E2A; Backend &#x8DEF;&#x5F84;&#x4E0B;&#x6240;&#x6709;&#x5176;&#x4ED6; Workspace&#xFF1B;&#x53E6;&#x5916; Workspace &#x662F;&#x9690;&#x5F0F;&#x914D;&#x7F6E;&#x7684;(&#x8C03;&#x7528;&#x547D;&#x4EE4;&#x884C;)&#xFF0C;&#x6240;&#x4EE5;&#x6709;&#x65F6;&#x4EBA;&#x4EEC;&#x4F1A;&#x5FD8;&#x8BB0;&#x81EA;&#x5DF1;&#x5DE5;&#x4F5C;&#x5728;&#x54EA;&#x4E2A; Workspace &#x4E0B;&#x3002;</p>
<p>Terraform &#x5B98;&#x65B9;&#x4E3A; Workspace &#x8BBE;&#x8BA1;&#x7684;&#x573A;&#x666F;&#x662F;&#xFF1A;&#x6709;&#x65F6;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x60F3;&#x8981;&#x5BF9;&#x65E2;&#x6709;&#x7684;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x505A;&#x4E00;&#x4E9B;&#x53D8;&#x66F4;&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x6D4B;&#x8BD5;&#xFF0C;&#x4F46;&#x53C8;&#x4E0D;&#x60F3;&#x76F4;&#x63A5;&#x5192;&#x9669;&#x4FEE;&#x6539;&#x65E2;&#x6709;&#x7684;&#x73AF;&#x5883;&#x3002;&#x8FD9;&#x65F6;&#x4ED6;&#x53EF;&#x4EE5;&#x5229;&#x7528; Workspace &#x590D;&#x5236;&#x51FA;&#x4E00;&#x4E2A;&#x4E0E;&#x65E2;&#x6709;&#x73AF;&#x5883;&#x5B8C;&#x5168;&#x4E00;&#x81F4;&#x7684;&#x5E73;&#x884C;&#x73AF;&#x5883;&#xFF0C;&#x5728;&#x8FD9;&#x4E2A;&#x5E73;&#x884C;&#x73AF;&#x5883;&#x91CC;&#x505A;&#x4E00;&#x4E9B;&#x53D8;&#x66F4;&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x6D4B;&#x8BD5;&#x548C;&#x5B9E;&#x9A8C;&#x5DE5;&#x4F5C;&#x3002;</p>
<p>Workspace &#x5BF9;&#x5E94;&#x7684;&#x6E90;&#x4EE3;&#x7801;&#x7BA1;&#x7406;&#x6A21;&#x578B;&#x91CC;&#x7684;&#x4E3B;&#x5E72;&#x2014;&#x2014;&#x5206;&#x652F;&#x6A21;&#x578B;&#xFF0C;&#x5982;&#x679C;&#x56E2;&#x961F;&#x5E0C;&#x671B;&#x7EF4;&#x62A4;&#x7684;&#x662F;&#x4E0D;&#x540C;&#x4EA7;&#x54C1;&#x4E4B;&#x95F4;&#x4E0D;&#x540C;&#x7684;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#xFF0C;&#x6216;&#x662F;&#x5F00;&#x53D1;&#x3001;&#x6D4B;&#x8BD5;&#x3001;&#x9884;&#x53D1;&#x5E03;&#x3001;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#xFF0C;&#x90A3;&#x4E48;&#x6700;&#x597D;&#x8FD8;&#x662F;&#x4F7F;&#x7528;&#x4E0D;&#x540C;&#x7684;&#x6587;&#x4EF6;&#x5939;&#x4EE5;&#x53CA;&#x4E0D;&#x540C;&#x7684; <code>backend-config</code> &#x8FDB;&#x884C;&#x7BA1;&#x7406;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2.1.Terraform基础概念——Provider.html" class="navigation navigation-prev " aria-label="Previous page: Provider">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="3.Terraform代码的书写.html" class="navigation navigation-next " aria-label="Next page: Terraform 代码的书写">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"状态管理","level":"1.3.2","depth":2,"next":{"title":"Terraform 代码的书写","level":"1.4","depth":1,"path":"3.Terraform代码的书写.md","ref":"./3.Terraform代码的书写.md","articles":[{"title":"类型","level":"1.4.1","depth":2,"path":"3.1.类型.md","ref":"./3.1.类型.md","articles":[]},{"title":"配置语法","level":"1.4.2","depth":2,"path":"3.2.配置语法.md","ref":"./3.2.配置语法.md","articles":[]},{"title":"输入变量","level":"1.4.3","depth":2,"path":"3.3.输入变量.md","ref":"./3.3.输入变量.md","articles":[]},{"title":"输出值","level":"1.4.4","depth":2,"path":"3.4.输出值.md","ref":"./3.4.输出值.md","articles":[]},{"title":"局部值","level":"1.4.5","depth":2,"path":"3.5.局部值.md","ref":"./3.5.局部值.md","articles":[]},{"title":"资源","level":"1.4.6","depth":2,"path":"3.6.资源.md","ref":"./3.6.资源.md","articles":[]},{"title":"数据源","level":"1.4.7","depth":2,"path":"3.7.数据源.md","ref":"./3.7.数据源.md","articles":[]},{"title":"表达式","level":"1.4.8","depth":2,"path":"3.8.表达式.md","ref":"./3.8.表达式.md","articles":[]},{"title":"重载文件","level":"1.4.9","depth":2,"path":"3.9.重载文件.md","ref":"./3.9.重载文件.md","articles":[]},{"title":"代码风格规范","level":"1.4.10","depth":2,"path":"3.10.代码风格规范.md","ref":"./3.10.代码风格规范.md","articles":[]},{"title":"Checks","level":"1.4.11","depth":2,"path":"3.11.checks.md","ref":"./3.11.checks.md","articles":[]}]},"previous":{"title":"Provider","level":"1.3.1","depth":2,"path":"2.1.Terraform基础概念——Provider.md","ref":"./2.1.Terraform基础概念——Provider.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-highlight","prism","prism-themes","fontsettings","sharing","-lunr","-search","search-pro","livereload","image-captions","sitemap-general","anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prism-themes/themes/prism-vsc-dark-plus.css"],"lang":{"shell":"bash","cmd":"bash"}},"livereload":{},"search-pro":{},"sitemap-general":{"prefix":"https://lonegunmanb.github.io/introduction-terraform/"},"fontsettings":{"family":"sans","size":2,"theme":"white"},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"prism-themes":{},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"image-captions":{"caption":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","variable_name":"_pictures"}},"theme":"default","author":"大可不加冰","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[{"backlink":"index.html#fig1.1.1","level":"1.1","list_caption":"Figure: Nomad、Consul、Vault、Terraform 组成的 HashiStack","alt":"Nomad、Consul、Vault、Terraform 组成的 HashiStack","nro":1,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-13/1605243540985-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Nomad、Consul、Vault、Terraform 组成的 HashiStack","attributes":{},"skip":false,"key":"1.1.1"},{"backlink":"index.html#fig1.1.2","level":"1.1","list_caption":"Figure: Terraform 著名教材《Terraform Up & Running》，建议直接阅读第二版","alt":"Terraform 著名教材《Terraform Up & Running》，建议直接阅读第二版","nro":2,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-12-23/1608689176373-image.png","index":2,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Terraform 著名教材《Terraform Up & Running》，建议直接阅读第二版","attributes":{},"skip":false,"key":"1.1.2"},{"backlink":"./2.1.Terraform基础概念——Provider.html#fig1.3.1.1","level":"1.3.1","list_caption":"Figure: Terraform通过RPC调用插件，插件代码通过调用SDK操作远程资源","alt":"Terraform通过RPC调用插件，插件代码通过调用SDK操作远程资源","nro":3,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-16/1605496195438-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Terraform通过RPC调用插件，插件代码通过调用SDK操作远程资源","attributes":{},"skip":false,"key":"1.3.1.1"},{"backlink":"./2.1.Terraform基础概念——Provider.html#fig1.3.1.2","level":"1.3.1","list_caption":"Figure: registry.terraform.io上的插件页面","alt":"registry.terraform.io上的插件页面","nro":4,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-19/1605799350775-image.png","index":2,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"registry.terraform.io上的插件页面","attributes":{},"skip":false,"key":"1.3.1.2"},{"backlink":"./2.1.Terraform基础概念——Provider.html#fig1.3.1.3","level":"1.3.1","list_caption":"Figure: registry.terraform.io的搜索页面","alt":"registry.terraform.io的搜索页面","nro":5,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-16/1605498907942-image.png","index":3,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"registry.terraform.io的搜索页面","attributes":{},"skip":false,"key":"1.3.1.3"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.1","level":"1.3.2","list_caption":"Figure: Consul的GUI界面","alt":"Consul的GUI界面","nro":6,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220224455.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Consul的GUI界面","attributes":{},"skip":false,"key":"1.3.2.1"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.2","level":"1.3.2","list_caption":"Figure: Consul 中可以看到名为 `localstack-aws` 的键","alt":"Consul 中可以看到名为 `localstack-aws` 的键","nro":7,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230042.png","index":2,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Consul 中可以看到名为 `localstack-aws` 的键","attributes":{},"skip":false,"key":"1.3.2.2"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.3","level":"1.3.2","list_caption":"Figure: 键的内容","alt":"键的内容","nro":8,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230136.png","index":3,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"键的内容","attributes":{},"skip":false,"key":"1.3.2.3"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.4","level":"1.3.2","list_caption":"Figure: 键依然存在","alt":"键依然存在","nro":9,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230312.png","index":4,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"键依然存在","attributes":{},"skip":false,"key":"1.3.2.4"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.5","level":"1.3.2","list_caption":"Figure: 内容已被清空","alt":"内容已被清空","nro":10,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240220230350.png","index":5,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"内容已被清空","attributes":{},"skip":false,"key":"1.3.2.5"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.6","level":"1.3.2","list_caption":"Figure: 多了一个同名的文件夹","alt":"多了一个同名的文件夹","nro":11,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225100309.png","index":6,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"多了一个同名的文件夹","attributes":{},"skip":false,"key":"1.3.2.6"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.7","level":"1.3.2","list_caption":"Figure: localstack-aws 文件夹内部","alt":"localstack-aws 文件夹内部","nro":12,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225100354.png","index":7,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"localstack-aws 文件夹内部","attributes":{},"skip":false,"key":"1.3.2.7"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.8","level":"1.3.2","list_caption":"Figure: `.lock` 内容","alt":"`.lock` 内容","nro":13,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180803.png","index":8,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"`.lock` 内容","attributes":{},"skip":false,"key":"1.3.2.8"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.9","level":"1.3.2","list_caption":"Figure: `.lockinfo` 内容","alt":"`.lockinfo` 内容","nro":14,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180852.png","index":9,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"`.lockinfo` 内容","attributes":{},"skip":false,"key":"1.3.2.9"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.10","level":"1.3.2","list_caption":"Figure: 重新访问Consul","alt":"重新访问Consul","nro":15,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225101100.png","index":10,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"重新访问Consul","attributes":{},"skip":false,"key":"1.3.2.10"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.11","level":"1.3.2","list_caption":"Figure: 将代码复制到不同的文件夹中保存","alt":"将代码复制到不同的文件夹中保存","nro":16,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-17/1605571444613-image.png","index":11,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"将代码复制到不同的文件夹中保存","attributes":{},"skip":false,"key":"1.3.2.11"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.12","level":"1.3.2","list_caption":"Figure: 重新访问 Consul，目前有一个键","alt":"重新访问 Consul，目前有一个键","nro":17,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225174932.png","index":12,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"重新访问 Consul，目前有一个键","attributes":{},"skip":false,"key":"1.3.2.12"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.13","level":"1.3.2","list_caption":"Figure: Consul 中多了一个 `localstack-aws-env:feature1`","alt":"Consul 中多了一个 `localstack-aws-env:feature1`","nro":18,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225175538.png","index":13,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Consul 中多了一个 `localstack-aws-env:feature1`","attributes":{},"skip":false,"key":"1.3.2.13"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.14","level":"1.3.2","list_caption":"Figure: 此时 `localstack-aws-env:feature1` 的内容","alt":"此时 `localstack-aws-env:feature1` 的内容","nro":19,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225175806.png","index":14,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"此时 `localstack-aws-env:feature1` 的内容","attributes":{},"skip":false,"key":"1.3.2.14"},{"backlink":"./2.2.Terraform基础概念——状态管理.html#fig1.3.2.15","level":"1.3.2","list_caption":"Figure: `localstack-aws-env:feature1` 被删除了","alt":"`localstack-aws-env:feature1` 被删除了","nro":20,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/20240225180126.png","index":15,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"`localstack-aws-env:feature1` 被删除了","attributes":{},"skip":false,"key":"1.3.2.15"},{"backlink":"./5.10.graph.html#fig1.6.10.1","level":"1.6.10","list_caption":"Figure: 生成的依赖图","alt":"生成的依赖图","nro":21,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2020-11-25/1606272727693-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"生成的依赖图","attributes":{},"skip":false,"key":"1.6.10.1"},{"backlink":"8.CloudPosse最佳实践.html#fig1.9.1","level":"1.9","list_caption":"Figure: Terraform 输出值的命名要对称","alt":"Terraform 输出值的命名要对称","nro":22,"url":"https://raw.githubusercontent.com/lonegunmanb/introduction-to-terraform-pic/master/2021-11-28/1638086002974-image.png","index":1,"caption_template":"图 _PAGE_LEVEL_/_PAGE_IMAGE_NUMBER_ - _CAPTION_","label":"Terraform 输出值的命名要对称","attributes":{},"skip":false,"key":"1.9.1"}]},"title":"《Terraform入门教程》","gitbook":"*"},"file":{"path":"2.2.Terraform基础概念——状态管理.md","mtime":"2024-06-23T14:19:10.989Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-06-24T12:39:39.308Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    

    </body>
</html>

